0

I have setup a Moquette MQTT broker and connected it with eclipse Paho client (I will call this paho1). Subscribing to in/# topic.

I created another Paho client (I will call this paho2), with a different client id of course, and published it to the broker with in/device topic.

At first, the packet was delivered successfully. However, when I disconnect paho2 and reconnect to the broker and send the same packet, it is not delivered to paho1.

I wonder why this is happening. My settings for the Paho client is qos = 0 (I tried 1 and 2 as well).

MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(false);

I was looking at the log of broker and it comes as follows. When successful, my protocol version is printed to the log.

when Succeeded

Failed

Magnilex
  • 11,584
  • 9
  • 62
  • 84
Jae Park
  • 621
  • 4
  • 13
  • 27
  • Do you definitely mean `in/*` not `in/#`? – ralight May 19 '15 at 20:55
  • @ralight I've changed to in/# I figured out that was wrong. Still, I ain't getting the message from the broker.. does MQTT broker filters the same packet? – Jae Park May 20 '15 at 07:46
  • I can see that broker is republishing the message to my paho2. however, the callback is not responding.. – Jae Park May 20 '15 at 07:59

1 Answers1

1

I would suggest trying to replicate the problem with different tools. With the broker running, run a subscribing client:

mosquitto_sub -h <hostname> -t in/# -v

Then separately do the publishing:

mosquitto_pub -h <hostname> -t in/device -m message

This should return very quickly and your mosquitto_sub instance should print in/device message. Repeat the publish and you should see the same thing.

If you do not see a repeated message, there is a problem with the broker. If would then try using e.g. mosquitto as the broker and repeating with your code.

If you do see the repeated message using mosquitto_pub/sub, your code is somehow at fault. You can carry on trying different permutations until you have a better idea where the problem lies - i.e. use mosquitto_pub+your sub, mosquitto_sub+your pub.

ralight
  • 11,033
  • 3
  • 49
  • 59
  • I tried this with spy-mqtt. seems like other client is receiving the messages correctly... seems like problem with my client then.. is it suggested to use publish client and subscribe client separately? – Jae Park May 21 '15 at 00:36
  • There's no need to have separate pub/sub clients. But isn't that what you're doing anyway with paho1 and paho2? Or are they two instances of a client within one program? – ralight May 21 '15 at 07:27
  • I found where the problem is occurring. I was calling publish or subscribe method from the callback method. This cause the client to be stuck for some reason. So I created another client to publish. Also I subscribed after the callback was handled. Now it is working well. – Jae Park May 29 '15 at 01:17