mqtt message delivery , after connection lost

2823 views
Skip to first unread message

titov

unread,
Sep 4, 2013, 6:20:10 PM9/4/13
to mq...@googlegroups.com
I am just getting started with mqtt , I have an application which sends out data asynchronously.I am using
the asynchronous mqtt paho client for this. I have set qos as 2 and clean session is true. The device in which
I am running my client application is a very limited device which gets disconnected from the data connection
most of the times due to intermittent network outages.So I am testing the reliability of the device to send data once
the connection resumes without ANY data loss.

I have handled connection lost aync callback and it tries to reconnect till it succeeds.

Another thread runs always and keep publishing data , the thread do not care whether the connection 
is ON or not , it just calls the publish method of my mqtt instance.

Here are my connection options.

library used =  mqtt paho client for java ( mqtt-client-0.4.0.jar )
clean session = true
qos = 2
keepalive = 60

My problem is Situation B.

Situation A ( Success ) ( A thread is relentessly publishing data to my async mqtt client instance , it do not care whether the client is connected or not  )

1) Good connectivity , published data is delivered , all good :)
2) NO data connectivity , connect lost callback is not called yet , because the keep alive limit not reached.
3) Thread is still pushing data to the mqtt client instance publish method.
4) I get back connectivity , before keep alive limit , all the pending messages are delivered ! all good.

Situation B ( Failure ) ( A thread is relentessly publishing data to my async mqtt client instance , it do not care whether the client is connected or not  )

1) Good connectivity , published data is delivered , all good :)
2) NO data connectivity , connect lost callback is not called yet , because the keep alive limit not reached.
3) Thread is still pushing data to the mqtt client instance publish method.
4) Still no connectivity , keep alive reached. connection lost is called. 
5) Thread is still pushing data to the mqtt client instance  publish method , only to get exception that "client is not connected"
6) I get back connectivity , the messages after data connectivity loss and before "connection lost" is delivered , good !
Problem --->
7) But the messages after "connection lost" till the connection regained are not anywhere to be seen.Its not delivered.


Is this the way the mqtt spec says  , or is there a technical problem. What I understood from the spec is Qos = 2 ensures data delivery , no matter what , even after the connection is lost , all the pending messages is 

supposed to be delivered once the connection comes back.
I would really appreciate any help on this. Situation B , scenario 7.






Nicholas O'Leary

unread,
Sep 4, 2013, 6:25:29 PM9/4/13
to mq...@googlegroups.com
Hi,

when you use clean session = true, then all session state is wiped when the client loses its connection.

From what you describe, you should be using clean session = false to ensure message state is saved.

Regards,
Nick


--
--
To learn more about MQTT please visit http://mqtt.org
 
To post to this group, send email to mq...@googlegroups.com
To unsubscribe from this group, send email to
mqtt+uns...@googlegroups.com
 
For more options, visit this group at
http://groups.google.com/group/mqtt
 
---
You received this message because you are subscribed to the Google Groups "MQ Telemetry Transport" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mqtt+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Pablo Lopez

unread,
Jan 21, 2014, 6:50:14 PM1/21/14
to mq...@googlegroups.com
Hi Titov (and Nicholas)

I'm also a newby in Mqtt, but I haven't even been able to reproduce what you described is the A) case.

I have the same initial parameters as you had (Paho Java, Async client...), but as soon as I have a network outage, the publish method I call throw an exception :
Caused by: Client is not connected (32104)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:27)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:132)
at org.eclipse.paho.client.mqttv3.MqttTopic.publish(MqttTopic.java:65)

Could you please help me by providing your (working) code snippet, making the 'ignore if client is connected, publish anyway' work ? Thanks a lot.

Pablo

Pablo Lopez

unread,
Jan 22, 2014, 3:43:02 AM1/22/14
to mq...@googlegroups.com
Hi Titov (and Nicholas)

I'm a noob in the Mqtt and Paho world. I have exact same problematic as you had, unreliable network with a set of sensors linked to a Raspberry Pi. The Pis connect to a Mosquitto broker, when they can.

I used Paho with the MqttAsyncClient, but I was not able to reach the A) state you described. When the network goes down,  the publish method ends abruptly with a "Client is not connected (32104)" exception.
Going through the source, I saw that in the end, publish calls ClientComms#sendNoWait(MqttWireMessage message, MqttToken token) which first instruction is to check if isConnected() and throw the exception otherwise.

What am I missing ? Can you please provide your working code snippet, handling network outage ?

Thanks.

Pablo.
Reply all
Reply to author
Forward
0 new messages