Sunday, May 27, 2018

Publishing to Kapua with a Non-Kura Client

The Eclipse IoT framework is already very comprehensive and like all things stewarded by the Eclipse organization, seems to have a lot of momentum going for it. However, this is also the cutting edge of open source and documentation is sparse, often out of date and sometimes misleading.

I spent quite some time trying to figure out how to connect to a Kapua back end with anything other than a Kura client and could not find a satisfactory answer. This despite the fantastic efforts of community members like Ctron. I was looking for a simple non-Kura option, something that went beyond Kura simulators and the like.

Given that Kapua offers what is a MQTT interface as one of its connectivity options, one would have expected Paho or any good MQTT client solution to work I was quite frustrated to find using a simple Node-Red mqtt node did not quite work initially. The following is learning and the code that finally got it all working:

Things that I learnt:
  • You need to figure out where your Kapua Broker logs are being stored and watch them closely as you get your installation running. It is exhaustive and an excellent debugging option
  • If you use username password authentication as I am initially, you need to get your user roles and permissions right in the Kapua console
  • Once I had solved all the problems around getting the message to the broker, I saw this persistent but inexplicable message around unprocessable messages from Camel. Using mqtt-spy I eventually figured out that Kapua does not depend on Kura but has standardized on the Google ProtoBuf based data format for message encoding over MQTT
  • You need to honor Kapua / Kura topic naming semantics - at the very least your topic names should be in the form: /{account-name}/{client-id}/{app-id}
Check out the attached Java source code that uses Paho to connect to a Kapua installation. You should refer to the attached Maven pom that tells you what libraries I'm using as well.


Java source

Contents of pom.xml

Things to do: Check out https://www.eclipse.org/kapua/docs/0.3.0/developer-guide/en/client.html

No comments: