【问题标题】:Invald characters at start of message from Solace-MQ来自 Solace-MQ 的消息开头的无效字符
【发布时间】:2018-07-16 19:08:42
【问题描述】:

我们有两个 Java 应用程序,它们通过 solace-mq 相互通信。 Component-1 使用 JMS Publisher 将 JSON 消息写入队列。 Component-2 使用本地 Solace 消费者来消费它们。

问题是,Component-2 收到的消息在 JSON 大括号之前的消息开头包含无效字符。这是为什么?有没有其他人遇到过这个问题?

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

【问题讨论】:

  • 只是想知道您是否解决了这个问题?我在发送 TextMessage 时遇到了同样的问题

标签: java solace solace-mq


【解决方案1】:

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

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

要在开放 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 消费者应用程序。

【讨论】:

    猜你喜欢
    • 2017-05-13
    • 1970-01-01
    • 2012-05-08
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    相关资源
    最近更新 更多