Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] messages not delivered after reconnecting client with cleansession=false


>
> Hi,
>   
> I am using paho mqtt client for android, mosquitto is used as the mqtt broker.
>
> When the client re-connects with cleansession=false, the messages published when the client was disconnected is not delivered to the client, I did try with all the qos, same result.
>
> How do I make the messages to be delivered when the client reconnects ?
>
> Here is the code:
>
> public class MqttTest {
> private static String MQTT_SERVER="tcp://mqtt.broker.in:1883";
> private static String serial_no="my_unique_id";
> @SuppressWarnings("deprecation")
> public static void main(String[] args) throws ParseException {
> try{
> MemoryPersistence persistence = new MemoryPersistence();
> MqttClient client = new MqttClient(MQTT_SERVER, serial_no,persistence);
> MqttConnectOptions opts = new MqttConnectOptions();
> opts.setCleanSession(false);
> opts.setKeepAliveInterval(480);
> opts.setWill(client.getTopic("WillTopic"),
> "Something bad happened".getBytes(), 1, true);
> client.setCallback(new MqttCallback() {
> @Override
> public void connectionLost(Throwable arg0) {
> System.out.println("Connection lost:"+arg0.toString());
> }
> @Override
> public void deliveryComplete(IMqttDeliveryToken arg0) {
> // TODO Auto-generated method stub
> System.out.println("Delivery complete for:"+arg0.toString());
> }
> @Override
> public void messageArrived(String arg0, MqttMessage arg1)
> throws Exception {
> System.out.println("Message arrived, message:"+arg1.toString());
> }
> });
> client.connect(opts);
> if(client.isConnected()){
> //Subscribe to device updates
> client.subscribe("test_updates");
> }else{
> System.out.println("Not connected");
> }
> }catch(Exception e){
> e.printStackTrace();
> }
> }
>
> }
>


Back to the top