3
votes

I have this application using the mqtt-client java library to connect to an ActiveMQ broker via mqtt. The subscribing, publishing and receiving of the messages work fine as long as my topic does not have a forward slash (/).

I understand that forward slashs are special characters in mqtt and as per activemq mqtt support the "/" will be converted to ".". However, in my case, I need to connect to topics that have been created using JMS and which are written as an uri (example http://activemq.apache.org/) and will therefore have "/" on their names.

Is there anyway to scape the "/" on mqtt? At the moment, if I try connecting to a topic called http://activemq.apache.org/ it will in fact connect to http:..activemq.apache.org.

1
You can't escape the "/" on mqtt, I'm not sure what to suggest.ralight
This really needs answering by someone familiar with the activemq implementation. Your issue stems from how they have chosen to rewrite the topics - with seemingly no option to stop it doing so. If you don't get a useful response here, you should try via one of the activemq support channels.knolleary
@knolleary I checked their source and they replace the "/" for ".". Do you know by chance if as per mqtt standards, is mqtt supposed to accept topics with a "/" somehow escaped on their names? If so, I may try to push a change in the broker source (or change it myself), otherwise I should not try to convince it here not use such such topic namesThomas
@Thomas no, there is no concept of escaping the / in MQTT - so that suggests it is impossible, with ActiveMQ, to subscribe to a JMS-created topic that contains a / from an MQTT client. That seems a pretty big limitation, so worth following up with them.knolleary

1 Answers

2
votes

My Suggestion.. Only works if you're deploying your own ActiveMQ service..

Download the ActiveMQ source.. The conversions occur in the module MQTTProtocolConverter. There you'll see the special conversions.. The code has changed in 5.10.0, but needless to say you can escape stuff there and it should work. I modified the code for both inbound requests from MQTT and outbound.

I have had similar issues when trying to use MQTT and in the topics have '.''s E.G.

MQTT topic is /accounts/foobar/users/foo/storage/myText.txt

This is changed in the current implementation to

.accounts.foobar.users.foo.storage.myText.txt

and then when the message is received from MQTT plugin, the topic is converted to

/accounts/foobar/users/foo/storage/myText/txt

This is not what I wanted, so I had to modify the Converter to escape the '.' The result was the JMS toipc turn into

.accounts.foobar.users.foo.storage.myText\.txt

which worked..