Skip to main content

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

Hi,

using the code you provided, I am not able to recreate the failure you describe. I did the following:

1. Run MqttTest to establish the subscription, kill it.
2. From another client, publish three messages to the topic 'test_updates' - one at each of the three qos levels
3. Re-run MqttTest.

Result: the client receives the QoS 1 and QoS 2 messages published whilst not connected. As expected, the QoS 0 message is not stored for delivery if the client is not connected.

Are you running a slightly different scenario?

Regards,
Nick


On 14 July 2013 13:19, mahendra N <mahendra0203@xxxxxxxxx> wrote:


>
> 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();
> }
> }
>
> }
>


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/paho-dev



Back to the top