如何从MQTT产生并在ActiveMQ中作为MQTT和JMS进行消费 [英] How to Produce from MQTT and consume as MQTT and JMS in ActiveMQ

查看:203
本文介绍了如何从MQTT产生并在ActiveMQ中作为MQTT和JMS进行消费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置,其中将消息作为MQTT生成到ActiveMQ. 我有两个使用者,一个是JMS,另一个是MQTT.

I have a setup where messages are produced as MQTT to ActiveMQ. I have two consumers one as JMS and another MQTT.

当我将消息作为JMS消息发布到主题"foo"时,我在JMS和MQTT使用者上都收到消息,但是当我在同一主题上作为MQTT进行发布时,我仅在MQTT使用者上收到消息,并且JMS使用者什么也没收到.

When I am publishing message as JMS Message to the topic "foo", I am receiving the messages at both JMS and MQTT consumers, but when I am publishing as MQTT on the same topic I receive the message only on MQTT consumer and nothing at all is received at JMS consumer.

在以MQTT发行时,是否需要做一些特别的事情,以便能够以MQTT和JMS的形式使用.

Is there something I need to do specifically when publishing as MQTT to be able to consume as MQTT as well as JMS.

请帮助.

更新:

JMS使用者
JMS生产者
MQTT发布者
MQTT订阅者
activemq.xml

JMS Consumer
JMS Producer
MQTT Publisher
MQTT Subscriber
activemq.xml

推荐答案

您的问题似乎是您的JMS使用者希望消息以TextMessage的形式到达,这是在处理MQTT产生的消息时的错误假设.

Your problem looks to be that your JMS consumer is expecting the messages to arrive as a TextMessage which is a false assumption when dealing with MQTT produced messages.

MQTT消息是二进制的,没有内容类型信息或标头来定义有效负载.出于这个原因,代理将始终将它们解释为BytesMessage并以此进行分发.您将需要为该事实编写代码,并同时使用BytesMessage,然后将有效内容读取为String.

MQTT messages are binary with no content type information or headers to define the payload. For that reason the broker will always interpret them as a BytesMessage and dispatch them as such. You will need to code for that fact and consume BytesMessage as well, and then read the payload out as a String.

这篇关于如何从MQTT产生并在ActiveMQ中作为MQTT和JMS进行消费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆