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

Can we share MqttClient between verticles? #219

Closed
alamothe opened this issue Jun 1, 2022 · 7 comments
Closed

Can we share MqttClient between verticles? #219

alamothe opened this issue Jun 1, 2022 · 7 comments
Labels

Comments

@alamothe
Copy link

alamothe commented Jun 1, 2022

Read the docs and issues but haven't found this answered anywhere.

Is it safe to share MqttClient between verticles? Or should each verticle have its own MqttClient?

How is this different/same compared to HttpClient?

Thank you

@alamothe alamothe added the bug label Jun 1, 2022
@pigbayspy
Copy link
Contributor

No, you should not do this. I think it can not be shared by different verticle instances.

Please see this eclipse-vertx/vert.x#1248 (comment)

@vietj
Copy link
Contributor

vietj commented Aug 4, 2022

I think you can share a client between verticles, however handler will be called on a single event-loop that created the client.

@vietj vietj added the question label Aug 4, 2022
@pigbayspy
Copy link
Contributor

I think you can share a client between verticles, however handler will be called on a single event-loop that created the client.

In my impression, each verticle should have its own client. Is it a good way to share client between different verticle?

@vietj
Copy link
Contributor

vietj commented Aug 4, 2022 via email

@alamothe
Copy link
Author

That's a huge gotcha, as it almost certainly means you have to deal with multi-threaded programming, which defeats the purpose of using Vert.x in the first place. So from the user perspective in 99% of cases the clients should not be shared.

However appreciate you explaining the constraints clearly.

@vietj
Copy link
Contributor

vietj commented Aug 11, 2022

it's not really multi threaded because all processing message is done in a single event-loop.

Also I think the API usability could be improved and deal with multiple contexts, e.g now we have subscribe and process which are two separate operations:

client.publishHandler(s -> {
  System.out.println("There are new message in topic: " + s.topicName());
  System.out.println("Content(as string) of the message: " + s.payload().toString());
  System.out.println("QoS: " + s.qosLevel());
}).subscribe("rpi2/temp", 2);

instead we could have:

client.subscribe("rpi2/temp", 2, s -> {
  System.out.println("There are new message in topic: " + s.topicName());
  System.out.println("Content(as string) of the message: " + s.payload().toString());
  System.out.println("QoS: " + s.qosLevel());
};

the message would be delivered on the context of the subscriber and not on the context of the connection.

If the client is confined within a verticle, it would behave like it does currently.

There are other operations that could be improved with such correlations.

@vietj vietj removed the bug label Aug 11, 2022
@vietj vietj closed this as not planned Won't fix, can't repro, duplicate, stale Aug 11, 2022
@vietj
Copy link
Contributor

vietj commented Aug 11, 2022

See #228

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

No branches or pull requests

3 participants