【问题标题】:JMS, ActiveMQ - weird string prepended to my text message bodyJMS,ActiveMQ - 附加到我的短信正文的奇怪字符串
【发布时间】:2022-01-03 16:06:12
【问题描述】:

我正在开发一个生产者-消费者应用程序。两者通过一个 ActiveMQ 队列连接。 当我尝试发送消息时,在内容之前会添加以下字符串:

Sr�)�x-opt-jms-destQ�x-opt-jms-msg-typeQSs�d
�/ID:72a1faef-ff5a-40dd-aecc-61e94c0a432a:1:1:1-1@�queue://name_of_my_queue@@@@@@�~
�Sw�
actual message

消息被消费者检测为 ActiveMQBytesMessage,因此无法正确获取其内容。 以下是生产者和消费者的代码 sn-ps:

消费者

 String receiveMessage() {
  MessageConsumer consumer = session.createConsumer(session.createQueue(receiverQueue));
  String content = "";


  try {
    Message message = consumer.receive();
    if(message instanceof TextMessage) {
      content = ((TextMessage) message).getText(); 
    }
    else {
      BytesMessage byteMessage = (BytesMessage) message;
      byte[] byteData = null;
      byteData = new byte[(int) byteMessage.getBodyLength()];
      byteMessage.readBytes(byteData);
      byteMessage.reset();
      content =  new String(byteData);
    }
  }
  catch (JMSException | JsonProcessingException e) {
    log.error(e.getMessage());
  }
  return content;
}

制片人

void sendMessage() {
   JMSContext context;

    try {
       context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE);
        JMSProducer producer = context.createProducer();
        TextMessage tm = context.createTextMessage("TestMessage");
        producer.send(context.createQueue(myQueue), tm);
      }
    }
    catch (JMSException | JsonProcessingException e) {
       System.out.println(e.getMessage());
    }
}

生产者在 quarkus 应用程序中。 我怎么解决这个问题?谢谢!

【问题讨论】:

  • 也许您没有使用正确的编码?
  • 你使用的是什么版本的 ActiveMQ?
  • 我发现问题与代理有关:我使用的是 rmohr/activemq,切换到 artemis-activemq 解决了问题
  • 请将您的解决方案放入实际答案并标记为正确,以帮助将来遇到此问题的其他人。谢谢!

标签: java jms activemq quarkus


【解决方案1】:

对于那些可能遇到同样问题的人:我发现问题出在经纪人身上。我使用的是 rmohr/activemq 容器,我通过切换到 vromero/activemq-artemis 解决了这个问题

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2018-10-25
  • 2018-05-29
  • 2014-01-20
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多