Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] 回复: How to receive a "last will" message

Publisher or subscriber? The last will is sent as part of the connect message. Saying "now that I'm connected, should you find an unexpected disconnect publish this message to this topic."

What broker are you using? Once I figured out the semantics of not sending on a polite disconnect I found Mosquitto to be very reliable.


On Aug 24, 2013 3:07 AM, "灰(Grey)狼" <86267306@xxxxxx> wrote:
Thxs Darren  , How to make "last will" trigger , I have tried a lot : disuse the network of subscriber , make a exception , run System.exit(1) or just terminate the subscriber .

------------------ 原始邮件 ------------------
发件人: "Darren Clark"<dclark@xxxxxxxxxxxxx>;
发送时间: 2013年8月24日(星期六) 下午5:48
收件人: "General development discussions for paho project"<paho-dev@xxxxxxxxxxx>;
主题: Re: [paho-dev] How to receive a "last will" message

Not sure if it's the same, probably depends on the client and where the exception happens, but  I was a bit confused at first about LWT. It is a message posted by the broker when it sees the client disconnect unexpectedly, not just any disconnect.

So if the exception handling on the client causes it to send a disconnect message to the broker then the LWT won't be sent. It will only be sent if the socket is dropped or some other scenario without a valid disconnect being sent.


On Aug 24, 2013 2:14 AM, "灰(Grey)狼" <86267306@xxxxxx> wrote:


         I am confused how to receive a LWT messsge. I have set a last will in a subscriber A , the last will topic is called "lastwill". and start subscriber B to listen the "lastwill" topic .

         When I make some exception in Subscriber A ,to make the Subscriber disconnect from broker , no message arrived in subscriber B. I noticed some document said Server will
         publish the last will message. I spent lots of time and found no answer , any help will be appreciated , thanks.

   mqttClient = new MqttClient("tcp://", MqttClient.generateClientId());

   MqttConnectOptions connectOptions = new  MqttConnectOptions();

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




paho-dev mailing list

paho-dev mailing list

Back to the top