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

2.8k views Asked by At

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

ActiveMQ Web Console

1

There are 1 answers

0
Tim Bish On BEST ANSWER

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.