4

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?

1 Answer 1

2

So I ended up changing ActiveMQ keep-alive by configuring this line in activemq.xml:

<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?transport.defaultKeepAlive=10000"/>

And configuring the MQTT android client keep alive like so:

keepAliveSeconds = 5;
mqttClient.connect(mqttClientId, true, keepAliveSeconds);

I read that the client keep alive should be less than the server, this is why I choose 5 and 10 seconds. I hope this is the right amount of time for a real time application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.