EzDevInfo.com

MQTT.js

The MQTT client for Node.js and the browser

MQTT what is the purpose or usage of Last Will Testament?

I'm surely missing something about how the whole MQTT protocol works, as I can't grasp the usage pattern of Last Will Testament messages: what's their purpose?
One example I often see is about informing that a device has gone offline. It doesn't make very much sense to me, since it's obvious that if a device isn't publishing any data it may be offline or there could be some network problems.

So, what are some practical usages of the LWT? What was it invented for?


Source: (StackOverflow)

Synch and Asynchronous interface of MqttClient object are not working

I have created a client of type MqttClient and as shown below in the code, I create a client and se its Asynchronous callback. The problem is,

1-when I run the programm, the System.out.println("Client is Connected"); appears, but i receive no response fr0m the onSuccess or from oonFailure, why? wha I am doing wrong in the code.

2-i implemented the static IMqttAsyncClient asynchClientCB = new IMqttAsyncClient() interface, but since i have a client of type MqttClient, I can not use this IMqttAsyncClient interface. I tried to use mqttAsynchClien but because I program for java and not for Android i can not use it. How to use IMqttAsyncClient interface.?

Update_1

in the below code "Updated_code_1", i slightly modified the code, but i expect every time i connect successfully to the broker the message in onSuccess synchronous callback to be printed, and the message in onFailure synchronous callbck to be printed in case of the onnection terminated such as when i intentionally disconnect the network. But at ru time when I connect to the broker, neither onSuccess nor onFailur dispays any thing. So, what are they designed for?

*Update_2_17_Dec_2014

I have an inquiry that might lead us to a solution, which is, does it matter if I am connecting to the broker through wired/wire-less network? would that change the behaviour of he synchronous and Asynchronous listener?

Updated_1_code:

MqttConnectOptions opts = getClientOptions();
        client = MQTTClientFactory.newClient(broker, port, clientID);

        if (client != null) {
            System.out.println("Client is not Null");
            client.setCallback(AsynchCallBack);
            if (opts != null) {
                iMQTTToken = client.connectWithResult(opts);
                publishMSG(client, TOPIC,"010101".getBytes(), QoS, pub_isRetained);
                iMQTTToken.setActionCallback(synchCallBack);
                if (client.isConnected()) {
                    System.out.println("Client CONNECTED.");
                    publishMSG(client, TOPIC,"010101".getBytes(), QoS, pub_isRetained);
                }
            }
        }
    ....
    ....
    ....
    ....
IMqttToken iMQTTToken = new IMqttToken() {

    @Override
    public void waitForCompletion(long arg0) throws MqttException {
        // TODO Auto-generated method stub
        System.out.println("@waitForCompletion(): waiting " + (arg0 * 1000) + " seconds for connection to be established.");
    }

    @Override
    public void waitForCompletion() throws MqttException {
        // TODO Auto-generated method stub
        System.out.println("@waitForCompletion(): waiting for connection to be established.");
    }

    @Override
    public void setUserContext(Object arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void setActionCallback(IMqttActionListener arg0) {
        // TODO Auto-generated method stub
        arg0.onSuccess(iMQTTToken);
        //System.out.println(" " + arg0.onSuccess());
        //System.out.println(" " + arg0.onSuccess(iMQTTToken));
        iMQTTToken.setActionCallback(synchCallBack);
    }

    @Override
    public boolean isComplete() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Object getUserContext() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String[] getTopics() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean getSessionPresent() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public MqttWireMessage getResponse() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getMessageId() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int[] getGrantedQos() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public MqttException getException() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public IMqttAsyncClient getClient() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public IMqttActionListener getActionCallback() {
        // TODO Auto-generated method stub
        return null;
    }
};

IMqttActionListener synchCallBack = new IMqttActionListener() {

    @Override
    public void onSuccess(IMqttToken arg0) {
        // TODO Auto-generated method stub
        System.out.println("@onSuccess: Connection Successful.");
    }

    @Override
    public void onFailure(IMqttToken arg0, Throwable arg1) {
        // TODO Auto-generated method stub
        System.out.println("@onFailure: Connection Failed.");
        setViewEnableState(Bconnect, true);
    }
};

MqttCallback AsynchCallBack = new MqttCallback() {

    @Override
    public void messageArrived(String topic, MqttMessage msg) throws Exception {
        // TODO Auto-generated method stub
        System.out.println("@messageArrived: Message Delivered.");
    }

    @Override
    public void deliveryComplete(IMqttDeliveryToken token) {
        // TODO Auto-generated method stub
        System.out.println("@deliveryComplete: Delivery Completed.");
    }

    @Override
    public void connectionLost(Throwable thrw) {
        // TODO Auto-generated method stub
        System.out.println("@Connection Lost: Connection Lost.");
        setViewEnableState(Bconnect, true);
    }
};

Newclient:

    MqttConnectOptions opts = new MqttConnectOptions();
    opts.setCleanSession(CS);
    opts.setKeepAliveInterval(KATimer);
    HashMap<Integer, WILL> LWTData = WILLFactory.newWILL("LWT", "LWT MS".getBytes(), 1, false);
    opts.setWill(LWTData.get(0).getWILLTopic(), 
            LWTData.get(0).getWILLPayLoad(), 
            LWTData.get(0).getWILLQoS(), 
            LWTData.get(0).isWILLRetained());

    client = MQTTClientFactory.newClient(IP, PORT, clientID);

    if (client != null) {
        System.out.println("client is not null");

        client.setCallback(AsynchCB);
        IMqttToken token = client.connectWithResult(opts);

        if (client.isConnected()) {
            System.out.println("Client is Connected");

            token.setActionCallback(new IMqttActionListener() {

                public void onSuccess(IMqttToken arg0) {
                    // TODO Auto-generated method stub
                    System.out.println("synchCB->@onSuccess(): Connection Successful");

                    try {
                        client.subscribe(TOPIC, QoS);
                    } catch (MqttException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    try {
                        client.disconnect();
                    } catch (MqttException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                public void onFailure(IMqttToken arg0, Throwable arg1) {
                    // TODO Auto-generated method stub
                    System.out.println("synchCB->@onFailure(): Connection Failed");
                }
            });
        }else {
            System.out.println("client is not connected");
        }
    }else {
        System.out.println("client = null");
    }

Asynch CallBack:

/**
 * Asynchronous Callback to inform the user about events that might happens Asynchronously. If it is not used, any pending 
 * messages destined to the client would not be received.
 */
private static MqttCallback AsynchCB = new MqttCallback() {

    public void messageArrived(String topic, MqttMessage msg) throws Exception {
        // TODO Auto-generated method stub
        System.out.println("AsynchCB->@messageArrived(): ");

        System.out.println("Topic: " + topic);
        System.out.println("MSG: " + msg.toString());

    }

    public void deliveryComplete(IMqttDeliveryToken arg0) {
        // TODO Auto-generated method stub
        System.out.println("AsynchCB->@deliveryComplete(): ");
    }

    public void connectionLost(Throwable arg0) {
        // TODO Auto-generated method stub
        System.out.println("AsynchCB->@connectionLost(): ");
    }
};

Source: (StackOverflow)

Advertisements

MQTT Security - how to prevent abusers subscribing to topics?

I've got everything setup and working for MQTT now. I am using the IBM wmqtt.jar and the Mosquitto broker..

My Java Servlet creates an MQTTConnection to the broker and publishes under the topic "AndroidDeviceID/myAppName" ..

The Android client subscribes to that same topic...

It seems to me that if anyone knew the device name of my user, they could create a simple android app and subscribe to that topic on my MQTT broker. Then they get all the notifications (in this case instant messaging messages) from my users..

How is this properly avoided?


Source: (StackOverflow)

MQTT vs. XMPP Which Should I Choose?

Overview

I am sending messages back and forth between a client (Android phone) and a Server (Windows Server). Using a persistent connection over TCP, which protocol would be the best solution. I am looking at performance, scalability, size of messages, and battery life. The messages must arrive at the destination in order and can not be duplicates.

MQTT

This seems like the better solution, but there seems to be little examples of large implementation with lots of users. I am not sure if I can integrate this into the windows server, or if it would have to be another application or server running. Finally there seems to be a lack of information on it in general.

XMPP

This seems to have lots of implementation, examples, and even a book : ). However the main purpose seems to be for instant messaging clients and things like Google talk. Will this be an optimal solution to messaging between server and client. I know currently XMPP is mostly used in client to server to client architectures.

Please correct me if I am wrong and thanks in advance for any guidance.


Source: (StackOverflow)

Android & (millions of) push notifications

I'm working on the Android version of an application I first created on iPhone and this application requires to send (if it's as successful as its iPhone version) up to millions of push notifications to users daily.

I naively thought the Android platform had a push notifications service as its sibling so I decided to look at this feature at the end of development and now here i am!

I searched stackoverflow for answers about this feature (issue ?) and found several options (thanks guys!) BUT did any of you guys was able to achieve such a feature with such a volume?

Here's the options I found :

  • Google's C2DM Framework : my first issue is that it's for Android 2.2 + only but I may consider it if there wasn't this 200.000 notifications a day quota; did any of you guys requested more quota from Google ?
  • MQTT : this solution looks good and the sample code provided by Anton Lopyrev is helpful (and Dale Lane blog posts are a good read); this is the option I'm using right now but I have no idea about how it may react with thousand of users (I also have trouble with the server (mosquitto) OR the service (I don't know yet) and I am not able to receive notifications sometimes with 2 users :p)
  • XMPP : it looks like the best option (yet ?) but I haven't tried it yet; did any of you guys use this solution ?

I've read about Xtify or Urban Airship but none of these commercial solutions may help (volume or cost).

Thanks for any tips!

Edit : my goal is to be able to send up to 5,000,000 notifications a day


Source: (StackOverflow)

Basic Steps for Using MQTT in android

I am new to Android and want to use MQTT as push notifier for Android from Server.
i have read about MQTT but does not understand well. if any one has used this library so plz tell me what i have to do to start using it..

i have a Java Server (Running on Windows) and lots of Client(android phones on which my app will be installed). My server will send message to all or some specific clients at any time.

what are my basic requirement ? i mean is there

  1. server requirement ?
  2. some sort of registration ?
  3. Library to include in android ?
  4. identifier for Android device ? (as C2DM require Google account for each device)

plz help me in this regard


Source: (StackOverflow)

How to send ping using Eclipse Paho MQTT client?

We've just started building our own push notification system (due to client's requirement) for Android and found Eclipse Paho (http://www.eclipse.org/paho/). Needless to say, this project is really exciting.

The problem with Android is, if the CPU is in sleep state, the MQTT client may not get the chance to send ping at its set interval. The workaround is using AlarmManager to wake it up and get the job done. The Android documentation says:

The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock. This means that the phone will in some cases sleep as soon as your onReceive() method completes.

http://developer.android.com/reference/android/app/AlarmManager.html

I need to be sure that I could send the ping command within that onReceive() method while the CPU has PARTIAL_WAKE_LOCK, so I was searching a way to manually sending ping to server but it seems the client doesn't expose any such method. Am I missing something? Or, what is the workaround here except publishing my own "ping message"? I want to avoid that because of:

  1. Larger overhead
  2. We'll ensure that Android clients are subscriber only, may be with Mosquitto's ACL. They will not be allowed to publish messages.

Source: (StackOverflow)

Can a web browser use MQTT?

We are looking at using MQTT as the messaging protocol on a new device we're building. We'd also like a web interface for the device. Does anyone know if you can implement a browser client app (without additional plugins) that talks MQTT?


Source: (StackOverflow)

Thread issue while subscribing to MQTT in Python using Paho MQTT

I have a python program which listens to an MQTT topic and needs to process the message. I specify a number of arguments from the command line to evaluate the message differently.

import argparse
import datetime
import json

import paho.mqtt.client as mqtt

### MQTT Functions
def on_connect(mqttc, obj, flags, rc):
    print("Connected! - " + str(rc))

def on_message(mqttc, obj, msg):
    print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))

def on_publish(mqttc, obj, mid):
    print("Published! "+str(mid))

def on_subscribe(mqttc, obj, mid, granted_qos):
    print("Subscribed! - "+str(mid)+" "+str(granted_qos))

def on_log(mqttc, obj, level, string):
    print(string)

if __name__ == "__main__":
    # Handle args
    parser = argparse.ArgumentParser(
        description='This is to be usedin conjunction with the WifiScanner on a Raspberry Pi')
    parser.add_argument('--topic', metavar='base/sub', type=str, nargs='?', help='Full topic to listen to. (Example "proximity/sensor")', default="proximity/#")
    parser.add_argument('--host', metavar='url', type=str, nargs='?',
                        help='UQL of MQTT server.')
    parser.add_argument('--graph', metavar='True/False', type=bool, nargs='?', help='Whether to print the data.', default=True)
    parser.add_argument('--timeout', metavar='sec', type=int, nargs='?', help='How long the device will be remembered', default=10)
    args = parser.parse_args()
    # MQTT
    mqttc = mqtt.Client()
    # mqttc.on_message = on_message
    mqttc.on_connect = on_connect
    mqttc.on_publish = on_publish
    mqttc.on_subscribe = on_subscribe
    # Uncomment to enable debug messages
    #mqttc.on_log = on_log
    mqttc.connect(args.host, 1883, 60)
    mqttc.subscribe(args.topic, 0)
    # Start to listen    
    while True:
        print mqttc.loop()

The problem with this, is that I can't see an easy way to pass the command line arguments to the on_message callback. So I tried using the return value of .loop. However, when I try to exit using Ctrl+Z (only keyboard interrupt that works), it does not exit the MQTT threads and leaves them running.

The documentation and examples don't have an example on how to handle messages outside the on_message callback and how to cleanly exit.

So any help fixing this issue would be very appreciated.

Thanks in advance


Source: (StackOverflow)

Paho MQTT client behaviour when broker times out / client disconnects

I have a number of QoS2 level messages that are causing problems in the scenario when the MQTT broker or client is having issues. These issues can include

  • client starts to see server timeouts
  • client has lost connectivity with the broker (internet connection down , issue with the broker, ....) for a while and reconnects.

Typically, when the MQTT client starts receiving timeouts or other errors from the broker, the message are stored in the persistence storage (in-flight messages) and will eventually get republished.

However, in the case where the Paho client loses the connection to the broker, messages will not be considered in-flight anymore and will not be stored by Paho. At that point it seems that the app becomes responsible for persisting these msgs (outside of paho) and re-publishing them.

Am I correct in saying that when the MQTT broker becomes unavailable, the Paho MQTT client cannot help me out in guaranteeing that these QoS2 level messages will get re-delivered ?

So how can I make the distinction between the following case, where client.publish resulted in an MqttException where Paho did not persist the message inflight.

Client is currently disconnecting (32102)
    at org.eclipse.paho.client.mqttv3.internal.ClientComms.shutdownConnection(ClientComms.java:297)
    at org.eclipse.paho.client.mqttv3.internal.CommsSender.handleRunException(CommsSender.java:154)
    at org.eclipse.paho.client.mqttv3.internal.CommsSender.run(CommsSender.java:131)
    at java.lang.Thread.run(Thread.java:745)

And the following where it did persist it inflight

Timed out waiting for a response from the server (32000)
    at org.eclipse.paho.client.mqttv3.internal.Token.waitForCompletion(Token.java:94)
    at org.eclipse.paho.client.mqttv3.MqttToken.waitForCompletion(MqttToken.java:50)
    at org.eclipse.paho.client.mqttv3.MqttClient.publish(MqttClient.java:315)
    at org.eclipse.paho.client.mqttv3.MqttClient.publish(MqttClient.java:307)

Obviously I can also start doing bookkeeping and persist all failed messages seperately, but then I might end up with QoS level 2 duplicaties (messages getting both republished by Paho and myself).

How should the client be programmed ?

  • Do need a to do my own message persistence alongside Paho based on exception codes ?
  • Do I need to take into account the connectionLost callback and assume that from that point on Paho will not persist anything for me until the MQTT Client reconnects ?
  • Before publishing do I need to check if the client is properly connected, and if so assume that Paho will persist the message ?

Here are some exceptions and persistence behaviour by Paho

  • Connection lost (32109) : message is persisted by paho
  • Client is currently disconnecting (32102) : message is lost by paho
  • Timed out waiting for a response from the server (32000) : message is persisted paho
  • Client is not connected (32104) : message is lost by paho

What are some of the best practices here with Paho ?


Source: (StackOverflow)

Cannot receive already published messages to subscribed topic on mqtt paho

I'm using paho to send and receive mqtt messages. So far it has been no problem to send the messages. I have problems with receiving them.My code is:

     package BenchMQTT;

     import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
     import org.eclipse.paho.client.mqttv3.IMqttToken;
     import org.eclipse.paho.client.mqttv3.MqttCallback;
     import org.eclipse.paho.client.mqttv3.MqttException;
     import org.eclipse.paho.client.mqttv3.MqttMessage;
     import org.eclipse.paho.client.mqttv3.MqttClient;

     public class Test_A_2 implements MqttCallback {

     MqttClient clientR;
     MqttClient clientS;

     public Test_A_2() {
     }

     public static void main(String[] args) throws InterruptedException {
         long startTime = System.currentTimeMillis();
         new Test_A_2().doDemo();
         long endTime = System.currentTimeMillis();
     }

    public void doDemo() throws InterruptedException {
    try {   
    clientS = new MqttClient("tcp://mybroker:1883", "Sender");
    clientR = new MqttClient("tcp://mybroker:1883", "Reiever");
    clientR.connect();
    clientS.connect();
    MqttMessage message = new MqttMessage();

    String messagePayload = "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjk"
            + "lzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghj"
            + "klzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfgh"
            + "jklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfg"
            + "hjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasd"
            + "fghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopas"
            + "dfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopa"
            + "sdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiop"
            + "asdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuio"
            + "pasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyui"
            + "opasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyu"
            + "iopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwerty"
            + "uiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwert"
            + "nmqwertyuiop";

    clientR.subscribe("BenchMQTT");   
    clientR.setCallback(this);

    for(int i=0;i<10;i++)
    {
    message.setPayload((messagePayload)
            .getBytes());
    System.out.println(i);
    clientS.publish("BenchMQTT", message);
    }
    clientR.disconnect();   
    clientS.disconnect();
    clientR.close();   
    clientS.close();

   } catch (MqttException e)
    {
     System.out.println("ERROR");
    }
 }

     @Override
     public void connectionLost(Throwable cause) {
         // TODO Auto-generated method stub

     }

     @Override
     public void messageArrived(String topic, MqttMessage message)
     {
         System.out.println("Received: " + message.toString());
     }

     @Override
     public void deliveryComplete(IMqttDeliveryToken token) {

     }

     }

This send and receives messages.

OUTPUT:

0
Received: 0
1
Received: 1
2
Received: 2
3
Received: 3
4
Received: 4
5
Received: 5
6
Received: 6
7
Received: 7
8
Received: 8
9
Received: 9

I would like to send messages, and after that receive them. Any help? Expected OUTPUT:

0
1
2
3
4
5
6
7
8
9
Received: 0
Received: 1
Received: 2
Received: 3
Received: 4
Received: 5
Received: 6
Received: 7
Received: 8
Received: 9

Source: (StackOverflow)

again: Android MQTT unable to create client

I'm trying to create an MqttClient in Android, using an Android emulator (Nexus7) on ADT (Eclipse 3.8.0 on a Linux Fedora17. I found this question answered (Android MQTT unable to create client), but it failed to solve my problem.

I created an activity that allows the user to enter the directory where to store the presistence file, but there is no way to avoid catching the exception. I tried with "/mnt/sdcard/", "/mnt/", "/mnt/sdcard/tmp/" and similar.

Do I need to pay attention to particular settings in Android emulator on in Eclipse project? Are there any uses-permissions to be included in the application?

I looked at the various mqtt resources mentioned in the quoted answered question, but I couldn't manage to find an answer.

This is my code:

package com.storassa.android.mqttsample;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.TextView;

public class MqttSample extends Activity {

    Button okButton = null;
    AutoCompleteTextView inputTextView = null;
    TextView errorTextView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mqtt_sample);

        okButton = (Button)findViewById(R.id.okButton);
        inputTextView = (AutoCompleteTextView)findViewById(R.id.InputText);
        errorTextView = (TextView)findViewById(R.id.errorText);

        okButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                try {
                    String dir = inputTextView.getText().toString();
                    MqttDefaultFilePersistence mdfp = new MqttDefaultFilePersistence(
                            dir);
                    MqttClient client = new MqttClient("tcp://127.0.0.1:1833",
                            "0001", mdfp);
                }
                catch (Exception e) {
                    String errorText = "";
                    for (StackTraceElement error : e.getStackTrace())
                        errorText += error.toString() + "\n";
                    errorTextView.setText(errorText);
                }
            }
        });


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_mqtt_sample, menu);
        return true;
    }

}

and this is the Stack:

MqttException(0) at
org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:74)
org.eclipse.paho.client.mqttv3.MqttClient.<init>(MqttClient.java:183)
com.storassa.android.mqttsample.MqttSample$1.onClick(MqttSample.java:38)
android.view.View.performClick(View.java:4202)
android.view.View$PerformClick.run(View.java:17340)
android.os.Handler.handleCallback(Handler.java:725)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:5039)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
dalvik.system.NativeStart.main(Native Method)    

Source: (StackOverflow)

Android MQTT Client unable to reconnect to ActiveMQ

I'm using MQTT in android to communicate with an ActiveMQ server. I used this example to implement the android mqtt client: http://dalelane.co.uk/blog/?p=1599. When I first open the android app it connects to the ActiveMQ and everything works. When I close the application, delete the app data and reopen the android to try and reconnect to ActiveMQ I get the following error in ActiveMQ:

2013-09-29 19:25:50,064 | WARN  | Transport Connection to: tcp://192.168.0.108:54395 failed: java.io.EOFException | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///192.168.0.108:54395@1883
2013-09-29 20:18:20,417 | WARN  | Failed to add Connection ID:32132151513546-2:5, reason: javax.jms.InvalidClientIDException: Broker: localhost - Client: dbasdfasdfe0b already connected from tcp://192.168.0.108:59211 | org.apache.activemq.broker.TransportConnection | ActiveMQ Transport: tcp:///192.168.0.108:36745@1883

I'm guessing it has something to do with not disconnecting from the server before trying to reconnect. Maybe I can configure ActiveMQ to delete the unused connection and disconnect the client sooner when ActiveMQ figures that the client got disconnected?


Source: (StackOverflow)

MQTT client for iPhone

I am trying to follow this blog for building push services for iPhone. The blog uses Android as the working platform,but it can be migrated to iPhone too, provided I get an MQTT client in objective C..which I cant find anywhere. The closest I got to this is :

  1. I got a C implementation here - libmosquitto

  2. This post says I can use something like an HTTP bridge.

Can anyone please help me exploit these two options ? I dont know the next step to take :(

Thanks !!


Source: (StackOverflow)

MQTT messageId practical implementation

The company I am working for has evaluated MQTT and decided to use it as a core messaging platform for a large scale system. The main reason is how compact the protocol is and how easy it can actually be implemented. I have a single issue with MQTT though and I'm seeking for an answer to the following question:

QoS1 and QoS2 messages require confirmation from the client. The only thing I know about the message (identifying it) when receiving PUBACK, PUBREC, PUBREL and PUBCOMP is messageId and the clientId. Message id is an unsigned int16 so the max value is 65535. It doesn't seem to be large enough for long running clients, say a year, sending 15 QoS2 messages an hour.

I am not quite sure if there's any other way to identify the message? I would like to be as compliant with the standard as possible.


Source: (StackOverflow)