Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple connections #145

Open
3 of 5 tasks
woodrunner opened this issue Jan 3, 2020 · 11 comments
Open
3 of 5 tasks

Multiple connections #145

woodrunner opened this issue Jan 3, 2020 · 11 comments

Comments

@woodrunner
Copy link

  • I have searched for similar issues in this repository, but couldn't find one.
  • 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  
  • 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
@sclausen
Copy link
Owner

sclausen commented Jan 3, 2020

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?

@woodrunner
Copy link
Author

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.

@sclausen
Copy link
Owner

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.

@cedricve
Copy link

This would be very cool, I have also the requirement to connect to multiple brokers.

Regards
Cédric

@cedricve
Copy link

@sclausen is there any example that we could to this repo, for example in the examples folder?

@sclausen
Copy link
Owner

An example for usage is here or what do you mean?

@cedricve
Copy link

Sorry the comment was related to the one above. Illustrating the factory patttern.

@sclausen
Copy link
Owner

I posted a link to stackoverflow on an example how to use the factory pattern in the comment above

@cedricve
Copy link

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..

@sclausen
Copy link
Owner

sclausen commented Nov 10, 2020

I think the new setup with @angular/cli encourages examples inside a project. I'll put something together. Any wishes? @nosovk @AlxZchk @cedricve

@nosovk
Copy link
Contributor

nosovk commented Nov 11, 2020

Probably we can use https://www.emqx.io/mqtt/public-mqtt5-broker to avoid installing local broker for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants