eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 883 forks source link

Callback not invoked when using share subscription if publish and subscribe message on the same host #915

Open SomberOfShadow opened 2 years ago

SomberOfShadow commented 2 years ago

Hello everyone

Recently I use MQTT java paho client API, version is MQTTv5 1.2.5 on my local maven project.

I found a very strange issue:

If publish message to the topic and then subscribe this topic on the same host, it can not receive message usually, which callback is not invoked.

However, if publish messages to the topic on other host, then it will succeed to subscribe the topic and receive messages.

I don't know whether any others encounter this issue.

Looking forward to your reply.

Thanks you!

SomberOfShadow commented 2 years ago

After trouble-shooting, I found the root cause . I use thread pool to start publish client and another thread pool to start subscribe client, and use thread name as client Id. However, I don't know why these two thread pools' thread names are the same. As a result, the publish client Id and subscribe Id have conflicts.

Finally, I use "publish" as publish client id prefix and "subscribe" as subscribe client id prefix to solve this issue.