Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] how to use the new mqttPresistence, Qos and the acknowledge from the MQTT broker

Hi,
  I'm very, very interested to this topic. Can I try to summarize my understanding of how Paho works?

1. Messages published with QoS > 0 are considered "in-flight messages" and
    the acknowledgement phase/stage/state of every in-flight message is tracked in the persistence.
2. Paho does not retry the delivery of an in-flight message within the same "session"
    (I mean before a clean disconnect or the connection is lost).
    For example, if it does not receive a PUBACK to a message published with QoS == 1,
    it does not resend the original PUBLISH.
    Same for messages published with QoS == 2.
2.1 There is a maximum number of in-flight messages (10).
    If messages cannot be delivered (for example slow or broken link, e.g. GPRS),
    Paho will not accept more messages from the application.
    Note that the TCP/MQTT connection can still be healthy
    (accordingly to the value of the keep-alive intervals) even if the link is broken.
3. If Paho disconnects cleanly from the broker or the connection is lost,
    Paho will retry the delivery of in-flight messages in the next session but ONLY
    if its clean session flag is set to false. Otherwise the persistence will be cleared.
4  Not Paho specific, the semantics of QoS==2 can only be guaranteed across sessions established with clean session set to false.
    So, for example it won't be guaranteed if a client connects first with clean session==true,
    publishes some messages with QoS==2, loses the connection and
    reconnects later with clean session==false.
    If I'm not wrong Paho will not clear the persistence on the second session and might
    resend PUBLISH messages (with the duplicate flag set).
    On the broker side, since the first session was clean, the client state may have been deleted.
    Will the broker accept the duplicates as new messages in the second session or not?
    It's a corner case, I know...

Ciao,
  Cristiano


On 20/10/2015 11:04, James Sutton1 wrote:
Hi Peiyuan,
 
There is an example project here: https://github.com/IBMJames/EclipsePahoMavenExample that shows how to publish a message. It uses QoS and MemoryPersistence.
 
In the example, if the MQTT Broker is not contactable then an MqttException will be thrown.
 
Console output when working:
 
paho/EclipsePahoMavenExample [ java -cp target/my-app-1.0-SNAPSHOT-jar-with-dependencies.jar org.eclipse.paho.App                          master * ] 9:53 AM
Connecting to broker: tcp://iot.eclipse.org:1883
Connected
Publishing message: Message from MqttPublishSample
Message published
Disconnected
 
 
When the broker cannot be contacted:
 
paho/EclipsePahoMavenExample [ java -cp target/my-app-1.0-SNAPSHOT-jar-with-dependencies.jar org.eclipse.paho.App                          master * ] 9:53 AM
Connecting to broker: tcp://iot.ceclipse.org:1883
reason 32103
msg Unable to connect to server
loc Unable to connect to server
cause java.net.ConnectException: Connection refused
excep Unable to connect to server (32103) - java.net.ConnectException: Connection refused
Unable to connect to server (32103) - java.net.ConnectException: Connection refused
    at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:79)
    at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:619)
    at java.lang.Thread.run(Thread.java:781)
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:358)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:219)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:201)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:616)
    at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
    ... 2 more
 
 
Kind regards,
 
James Sutton
Software Engineer - IoT Foundation - MQTT Open Source Projects
Technical Trojan - Wimbledon Project

Phone: 01962 815438 | Extension: x372454
E-mail: james.sutton@xxxxxxxxxx
Personal Website: www.jsutton.co.uk
Find me on:      
IBM

Hursley Park
HursleySO212JN
United Kingdom
 
IBM United Kingdom Limited Registered in England and Wales with number 741598 Registered office: PO Box 41, North Harbour, Portsmouth, Hants. PO6 3AU
 
 
----- Original message -----
From: fang peiyuan <fang_peiyuan@xxxxxxxxx>
Sent by: paho-dev-bounces@xxxxxxxxxxx
To: "paho-dev@xxxxxxxxxxx" <paho-dev@xxxxxxxxxxx>
Cc:
Subject: [paho-dev] how to use the new mqttPresistence, Qos and the acknowledge from the MQTT broker
Date: Mon, Oct 19, 2015 7:34 AM
 
hi my name is peiyuan, currenly i am able to write a simple publisher and subscriber using java code and eclipse paho client thank to James.  Now i would like to go into QoS service and new MqttPresistence . So is there any tutorial or sample i can learn from it. 
 
At the same time i had problem in my current mqttpublisher how to return the connack from the broker server that i had connect to it? Because i want to know let say i forget to turn on my mosquitto server and hence i am not able to connect but currently even if i did not turn on my server, my client is still not a null and it till show is connected after i went through the debug mode 
 
my current code 
 
Mqttclient client = new Mqttclient (TCPaddress, ClientID, new Memorypresistence)
 
if (client != null)
{
    client .connect;
 
    if (!client.isconnected)
    {
        client.publish("topic", new MqttMessage("Message".getbytes));
}
 
thank you 
peiyuan 
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
 



_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

--
Cristiano De Alti
Principal Software Engineer

direct:    +39 0433 485468

EUROTECH
Imagine.Build.Succeed.
HEADQUARTERS
EUROTECH S.p.A. – Via Fratelli Solari, 3/a | 33020 Amaro UD | Italy | Tel. +39. 0433 485411  | Fax +39. 0433 485499 |
Cap. Soc. 8.878.946,00 € I.V. | P.IVA / C.F.: IT 01791330309 | REA Udine 196115
www.eurotech.com
____________________________________

Il presente messaggio ed ogni suo allegato sono da intendersi inviati esclusivamente agli effettivi destinatari e potrebbero essere soggetti a restrizioni legali. Se avete ricevuto questo messaggio per errore vi invitiamo a darne immediata notifica al mittente e cancellarlo dal vostro sistema. Qualsiasi altro uso di questo messaggio da parte vostra e' strettamente proibito.
 
This e-mail, and any file attached to it, is meant only for the intended recipient of the transmission and may be a communication privileged by law. If you have received it in error, please notify the sender immediately and delete the original from your system. Any other use of this e-mail by you is strictly forbidden.
____________________________________
 
Per favore, pensate all’ambiente prima di stampare questa e-mail. Please consider the environment before printing this e-mail.

Back to the top