4
votes

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
You should check that the topic names being used by the MQTT client to publish to all result in what your JMS client is subscribed to.Tim Bish
I am using topic name as "foo" for both JMS and MQTT publisher and subscriber. topic name does not looks like an issue to me.Sushil
I don't think anyone can answer without seeing code and views of the ActiveMQ WebConsole to see what destinations are getting created. Also use the latest ActiveMQ release to get all the bug fixes.Tim Bish
Hi, I have added the code and screenshot. I am using ActiveMQ 5.11.1Sushil

1 Answers

4
votes

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.