0

We have an two Java applications that communicate with each other via solace-mq. Component-1 uses a JMS Publisher to write JSON messages to the queue. Component-2 is using a native Solace consumer to consume them.

The problem is, the message Component-2 receives has invalid characters at the start of the message before the JSON open curly braces. Why is that? Has anybody else experienced this issue?

FYI The client we are using is sol-jcsmp-7.1.2.230

edb500
  • 313
  • 1
  • 3
  • 14
  • Just wondering if you resolved this issue? I am facing the same problem when sending a TextMessage – yifei Apr 14 '21 at 13:17

1 Answers1

0

What type of JMS message are you sending and how are you setting the payload? Also how are you extracting the payload in the consumer app?

Depending on the type of message you are creating in your JMS app, when received via Solace native Java API the payload maybe encoded in a different part of the message. For a JMS TextMessage it will be in the XML content part of the message (unless you have the JMS connection factory setting text-msg-xml-payload to be set to false) and for a JMS BytesMessage it will be in the Binary part of the message.

To correctly extract the payload when exchanging messages between open APIs and protocols do the following in your message receive callback XMLMessageLister.onReceive() method:

@Override
public void onReceive(BytesXMLMessage msg) {
    String messagePayload = "";

    if(msg.hasContent()) {
        // XML content part
        byte[] contentBytes = new byte[msg.getContentLength()];
        msg.readContentBytes(contentBytes);
        messagePayload = new String(contentBytes);
    } else if(msg.hasAttachment()) {
        // Binary attachment part
        ByteBuffer buffer = msg.getAttachmentByteBuffer();
        messagePayload = new String(buffer.array());
    }

    // Do something with the messagePayload like 
    // convert the String back to a JSON object
    System.out.println("Message received: " + messagePayload);
}

Also see the following documentation: https://docs.solace.com/Solace-JMS-API/Creating-JMS-Compatible-Msgs.htm if sending from Solace native API to a JMS consumer app.