How to read Java object after anypoint MQ subscriber

83 Views Asked by At

I am publishing the simple java payload into the anypointMQ publisher.

Input payload to anypointMQ publisher

%dw 2.0
output application/java
---
{
key1 : "value1" ,
key2 : "value2"
}

I am receiving the payload from subscriber, I am unable to read the payload. The payload coming as binary format. Please find the attachment. Please help how to read the payload. enter image description here

After anypointMQ subscriber, I am using the DW code as below.

%dw 2.0
output application/java
---
payload.^raw
1

There are 1 best solutions below

0
aled On

The body of an Anypoint MQ message is sent as a string as part of a JSON message. A Java object by default will be serialized in binary format that may be specific to the Java version. In a Mule application you should avoid relying on Java serialization so avoid using Java payloads. Instead use a format that has a textual representation like JSON or XML for objects. If you have to transfer binary data -excluding serialized Java objects- use the toBase64() function of the Binaries module.

Reference: https://docs.mulesoft.com/mq/mq-faq#how-can-i-send-a-java-object-as-a-message