How to Produce from MQTT and consume as MQTT and JMS in ActiveMQ

丶灬走出姿态 提交于 2019-12-22 09:55:22

问题


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

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.

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

Please help.

Update :

JMS Consumer
JMS Producer
MQTT Publisher
MQTT Subscriber
activemq.xml


回答1:


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 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.



来源:https://stackoverflow.com/questions/30723073/how-to-produce-from-mqtt-and-consume-as-mqtt-and-jms-in-activemq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!