Closed rubengees closed 3 years ago
Hi @rubengees Sorry for the delayed response. The same subscribe callback is called sequentially. This is necessary to uphold the MQTT message ordering guarantees (Actually it would be possible to distribute messages with different topics to different threads and still uphold the MQTT ordering guarantees. This may be done for the next major version, but your test uses the same topic so the callback will still be called in sequence in your case).
what can be done to actually concurrently handle messages?
You can of course decide to not care about the ordering and distribute the messages in the callback yourself like:
client.subscribe(...) { publish ->
threadPool.execute {
process(publish)
}
}
Alright, thanks for the answer!
@SgtSilvio are you planning to add this improvement for the 2.0.0? It could be useful in case of subscription via wildcard.
Expected behavior
When specifying a custom executor via the
applicationScheduler
on the builder, all threads of the underlying executor should be used to concurrently handle messages.Actual behavior
On high load the client seems to route the work only to a single thread. See reproduction code.
To Reproduce
Steps
Executors.newFixedThreadPool(2)
and configure to receive messages on a topic.Reproducer code
When running, this has the following output:
It can be seen that only one thread is used. The messages are getting delayed: After 10 messages, the subscriber is two behind.
When running the same code but with a delay in the publisher of 1100 instead of 800, the output is this:
Here, all threads are used, even though it would not be necessary.
Details
1.2.2
OpenJDK 64-Bit Server VM (build 16.0.1+9, mixed mode)
Arch Linux latest (2021-07-10)
5
EMQ X 4.3.1
Is this a usage problem, e.g. not configuring the thread pool correctly or might there be a bug either in this client or one of the dependencies? If not, what can be done to actually concurrently handle messages?