来自 Solace-MQ 的消息开头的字符



我们有两个Java应用程序,它们通过solace-mq相互通信。组件 1 使用 JMS 发布服务器将 JSON 消息写入队列。组件 2 使用本机 Solace 使用者来消费它们。

问题是,组件 2 收到的消息在 JSON 打开大括号之前的消息开头有无效字符。为什么?还有其他人遇到过这个问题吗?

仅供参考,我们使用的客户端是sol-jcsmp-7.1.2.230

您发送的 JMS 消息类型以及如何设置有效负载?另外,您如何在消费者应用程序中提取有效负载?

根据您在 JMS 应用程序中创建的消息类型,当通过 Solace 原生 Java API 接收时,有效负载可能会编码在消息的不同部分。对于 JMSTextMessage它将位于消息的 XML 内容部分(除非您将 JMS 连接出厂设置text-msg-xml-payload设置为 false),对于 JMSBytesMessage,它将位于消息的二进制部分。

要在开放 API 和协议之间交换消息时正确提取有效负载,请在消息接收回调XMLMessageLister.onReceive()方法中执行以下操作:

@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);
}

另请参阅以下文档:https://docs.solace.com/Solace-JMS-API/Creating-JMS-Compatible-Msgs.htm 是否从 Solace 本机 API 发送到 JMS 消费者应用程序。

最新更新