ngx-mqtt
ngx-mqtt copied to clipboard
Multiple connections
- [X] I have searched for similar issues in this repository, but couldn't find one.
- [X] I have read the README and have a basic understanding how angular works.
I'm submitting a...
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [ ] Bug report
- [X] Feature request
Current behavior
Is it currently possible to connect to multiple brokers in the same Angular app? Everytime I open a 2nd connection with a different hostname or port or query params, the old websocket gets closed.
Expected behavior
Connecting to multiple websocket brokers.
Environment
ngx-mqtt version: 6.13.2
Yes, you could use a factory for creating the service. the service and the underlying mqtt.js client instance uses one connection.
Adapting the code to support multiple connections/clients In the current service architecture would lead to many questions like which subscription should be made in which client and which publication publishes to which client and so on.
Could you elaborate how you want to use multiple connections to different brokers?
Thank you for your answer. I will try your solution!
Because we have a high availability setup for our platform, we stumble across certain issues where it comes down to losing messages if we only have one WebSocket open in one zone. Therefore, one WebSocket has to be set up for each zone so that both zones have their own WebSocket.
I don‘t think exposing high availability nodes to endpoints is a good idea, except you really don’t care about duplicate messages. A mqtt cluster solution for example is provided by HiveMQ, but your last comment sounded like the tech stack might be specified.
For your special requirements I actually would suggest changing the code so you can add multiple connections and subscribe and publish to all at once. I think this should not be incorporated in the master of this project, but it might be a solution for your issue.
This would be very cool, I have also the requirement to connect to multiple brokers.
Regards Cédric
@sclausen is there any example that we could to this repo, for example in the examples folder?
An example for usage is here or what do you mean?
Sorry the comment was related to the one above. Illustrating the factory patttern.
I posted a link to stackoverflow on an example how to use the factory pattern in the comment above
yes I know, and it works, I was just suggesting for upcoming users of your library, it might be good to document it inside the repo. So they do not end searching in the issue list (as what I've been doing).
From my opinion it's overkill to implement this feature into the source of your library. The dependency injection is good enough, but should be documented..
I think the new setup with @angular/cli
encourages examples inside a project. I'll put something together. Any wishes? @nosovk @AlxZchk @cedricve
Probably we can use https://www.emqx.io/mqtt/public-mqtt5-broker to avoid installing local broker for testing