Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Issue while publishing QOS 0 messages on Automatic re-connect

Well there was some debate as to whether QoS 0 messages ought to be "redelivered" on reconnect at all.  In fact an issue was raised saying that to do so was a bug. 

I had a conversation with James where I suggested it could be an option (whether to "redeliver" QoS 0 messages), but I don't know if he has added that yet, and he's on vacation at the moment.


On 08/23/2016 09:27 AM, Nidhi Kushwaha wrote:
Hi ,

When Connect/Automatic  reconnect is successful  I am publishing the messages/resume publishing.
If  QOS level is set to 0, messages are not getting published.Same code work fine with QOS set to 1 and 2.

Note:I am not using disconnected publishing as my queue requirement is different.

Attaching the code - 
public class MqttPublishQosIssue {
static MqttClient sampleClient = null;
private static final String topic = "MQTT Examples";
private static final String content = "Message from MqttPublishSample-";
private static final int qos = 0;
private static final String broker = "tcp://localhost:1883";
private static final String clientId = "JavaSample";
public static void main(String[] args) throws InterruptedException {
try {
sampleClient = new MqttClient(broker, clientId, new MemoryPersistence());
final MqttConnectOptions connOpts = new MqttConnectOptions();
sampleClient.setCallback(new MqttCallbackExtended() {
public void connectComplete(boolean reconnect, String serverURI) {
System.out.println("<< Connected to MQTT broker >> reconnect FLag" + reconnect);
try {
//Process Messages when connect is true/or automatic reconnect is true.
} catch (MqttException e) {
public void connectionLost(Throwable cause) {
System.out.println("<< Connection to MQTT broker lost >>" + cause.getMessage());

public void deliveryComplete(IMqttDeliveryToken token) {
System.out.println("<< Message was successfully delivered to MQTT>>");

public void messageArrived(String topic, MqttMessage message) throws Exception {
// Nothing to do

//No disconnect call as messages should be sent in a while loop

} catch (MqttException me) {
System.out.println("excep " + me);

private static void processMessages() throws MqttException, MqttPersistenceException {
System.out.println("[[Start processing of messages]]");
//Take incoming new + pending messages from user defined Q
MqttMessage message = new MqttMessage(content.getBytes());
message.setQos(qos);//QOS level is 0 message publish wont happen,Thread gets stuck !!.No callback's as well.
sampleClient.publish(topic, message);
System.out.println("[[End processing of messages]]");


paho-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Ian Craggs                          
icraggs@xxxxxxxxxx                 IBM United Kingdom
Paho Project Lead; Committer on Mosquitto

Back to the top