【问题标题】:ActiveMQ Spring Integration using MQTT topic使用 MQTT 主题的 ActiveMQ Spring 集成
【发布时间】:2016-01-30 17:43:49
【问题描述】:

我是activemq的新手。我在 activeMQ 中创建一个主题。并通过mqtt发布数据

mosquitto_pub   -d -t testTopic -m "test message"

但我收到一条错误消息

错误:消息不是预期的 TextMessage 类型。

这是我的代码

    public void onMessage(Message message) {
     if (message instanceof TextMessage) {


      }
      else
      {

        logger.error("Message is not of expected type TextMessage.");
      }
}

真正的问题是什么? .但是我通过http成功将数据发送到同一主题。

任何想法...???

【问题讨论】:

标签: java activemq mqtt spring-jms


【解决方案1】:

在ActiveMQ Spring consumer中,http消息是文本消息的类型,mqtt消息是BytesMessage的类型。因为我添加了一些代码

if (message instanceof BytesMessage) {
                BytesMessage bm = (BytesMessage) message;
                byte data[];
                data = new byte[(int) bm.getBodyLength()];
                bm.readBytes(data);
                msgText = new String(data);
                System.out.println("Message String = "+msgText);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 2013-12-10
    • 2016-05-08
    • 2014-08-23
    • 1970-01-01
    相关资源
    最近更新 更多