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 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
 


Back to the top