我们有两个Java应用程序,它们通过solace-mq相互通信。Component-1使用JMS发布器将JSON消息写入队列。Component-2使用本地的Solace消费者来使用它们。
问题是,接收的消息组件在JSON左花括号之前的消息开头有无效字符。为什么会这样呢?还有没有人遇到过这个问题?
仅供参考,我们使用的客户端是sol-jcsmp-7.1.2.230
发布于 2018-02-25 02:37:48
您发送的是什么类型的JMS消息,以及如何设置有效负载?另外,您如何提取消费者应用程序中的有效负载?
根据您在JMS应用程序中创建的消息的类型,当通过Solace原生Java API接收到有效负载时,可能会将其编码到消息的不同部分。对于JMS,它将位于消息的TextMessage内容部分(除非您将JMS连接工厂的text-msg-xml-payload设置为false),而对于JMS,它将位于消息的二进制部分。
要在开放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客户端应用程序。
https://stackoverflow.com/questions/48647787
复制相似问题