0

I am new to using loopback, and I'm using loopback4 (which I think is referred to as loopback-next)

I have set up my controllers, models & respositories in order to be able to support CRUD operations to mysql, and that is all fine.

I want my loopback application to also connect to an MQTT server, so that I can subscribe to messages from MQTT, and react to those messages by creating entities in my repositories. In addition, I want to be able to have existing controller methods drop messages onto the MQTT (publish)

I am struggling to understand the right way to do this in the loopback eco-system.

I don't think I want to create a Server - because the documentation describes a server as including a listen port. I don't want my loopback application to be a MQTT server. I just want it to interact with one.

Similarly, I don't think this would be an MQTT bridge, or a datasource.

I suspect, what I want is a service. But I'm not certain.

I would appreciate any advice on how to achieve this integration.

Thanks

jschank
  • 554
  • 1
  • 5
  • 16

1 Answers1

1

LB4 is highly extensible and a very good choice for such integrations. What you need in this case is to have a MQTT connector component. You can refer to the documentation for how to create a component in LB4 here and here.

You can refer to an example component implementation for authorization as well for quicker understanding.

Samarpan
  • 913
  • 5
  • 12
  • I've tried the suggestion, and I've built my component. I think it is the right track, however, I now have a problem accessing the repositories in my component. I think this is because of the order in which the bootstrapper works and when it binds things into the context. Specifically, how can my component reference repositories which already exist? (i.e. not provided by my component - though I bet that doesn't actually matter). I have tried to use a repository getter, and put the repository access into a Lifecycle start() method. But still no luck. – jschank Apr 27 '19 at 22:33
  • I can try to help if you can share the code you are trying with. – Samarpan Apr 29 '19 at 06:36
  • I was also in need of MQTT/AMQP functionality. I started creating my own extension which is now available at npm: https://www.npmjs.com/package/lb4-extension-mqtt. I'll add a readme in the next few days, but feel free to open an issue at github when you want some help with it – Jules May 02 '19 at 09:18
  • I appreciate the responses. Thanks SamyB and Jules. I decided to go another direction. Not so much because of loopback, but because of the way the javascript client MQTT.js works. (it allows many subscriptions, but they all come through the same 'on message' event, so you need to parse your topic strings and implement your own router. - as opposed to having separate handlers for each topic you subscribe to) So I switched to implementing my back-end in Go. Using gin-tonic, and SQL Boiler. And the paho go client for mqtt is pretty nice. While this comment is off topic, I thought I should share – jschank May 07 '19 at 13:00