greywolf created AMQ-4692:
-----------------------------

             Summary: ActiveMQ broker does not publish last will messages
                 Key: AMQ-4692
                 URL: https://issues.apache.org/jira/browse/AMQ-4692
             Project: ActiveMQ
          Issue Type: Bug
          Components: Broker, MQTT
    Affects Versions: 5.8.0
         Environment: win7 64 OS.
            Reporter: greywolf


When I run a MQTT client(paho or fuse)to connect ActiveMQ broker. if i 
terminate this client and can not receive LWT messages from broker.

I changed broker from ActiveMQ to Mosquitto broker , everything is ok.

below is my test class:

package com.paho;

import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttSecurityException;
import org.eclipse.paho.client.mqttv3.MqttTopic;

public class Sub {
        private MqttClient mqttClient;
        
        public void subscriber(){
                try {
                        mqttClient = new 
MqttClient("tcp://192.168.100.80:1883", MqttClient.generateClientId());
                        

                        MqttConnectOptions connectOptions = new  
MqttConnectOptions();

                        //set will
                        connectOptions.setWill(mqttClient.getTopic("lastwill"), 
new String("I am offline").getBytes(), 1, false);
                        mqttClient.connect(connectOptions);
                        mqttClient.setCallback(new MqttCallback(){

                                public void connectionLost(Throwable 
paramThrowable) {
                                        System.out.println("Connection Exist. 
\nCause: " + paramThrowable);
                                        while(true){
                                                try {
                                                        Thread.sleep(20000);
                                                        
if(!mqttClient.isConnected()){
                                                                subscriber();
                                                        }
                                                } catch (InterruptedException 
e) {
                                                        e.printStackTrace();
                                                }
                                        }
                                }

                                public void messageArrived(MqttTopic 
paramMqttTopic,
                                                MqttMessage paramMqttMessage) 
throws Exception {

                                        System.out.println("Message arrived 
From The Topic:\t"+paramMqttTopic.toString() +" \nMessage: " + 
paramMqttMessage.toString());
                                }

                                public void deliveryComplete(
                                                MqttDeliveryToken 
paramMqttDeliveryToken) {
                                }
                                
                        });
                        
                        mqttClient.subscribe("durable",1);
//                      mqttClient.subscribe("durable1",1);

                        
                } catch (MqttException e) {
                        e.printStackTrace();
                }

        }
        

        /**
         * @param args
         */
        public static void main(String[] args) {
                Sub sub = new Sub();
                sub.subscriber();
        }

}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to