Im trying to use Eclipse Paho MQTT client on my Android app to receive MQTT messages.
Im receiving ~100 message/second, messages are fairly small (basically small json objects). These messages are coming from Mosquitto broker.
When I subscribe to MQTT topic, and start to receive messages, my Android app UI almost freezes. I do not even do anything about the received message on messageArrived
callback.
My Eclipse Paho MQTT client usage is super basic, almost the same as in Eclipse Paho example.
Is Eclipse Paho MQTT client bad on performance, or is there something I might be doing wrong?
Im using:
org.eclipse.paho.client.mqttv3:1.1.0
& org.eclipse.paho.android.service:1.1.1
Update
Below my actual code, which is part of the fragment. So in this test im just logging the received message topic. Also with out logging, I got same result, my app almost freezes.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mqttAndroidClient = new MqttAndroidClient(getActivity().getApplicationContext(), "tcp://xx.xx.xx.xx:1883", MqttClient.generateClientId());
mqttAndroidClient.setCallback(new MqttCallbackExtended() {
@Override
public void connectComplete(boolean b, String s) {
}
@Override
public void connectionLost(Throwable throwable) {
}
@Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
Log.d("Mqtt", "messageArrived " + topic);
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
}
@Override
public void onStart() {
super.onStart();
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setCleanSession(true);
try {
mqttAndroidClient.connect(mqttConnectOptions, null, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
try {
mqttAndroidClient.subscribe("messages/#", 0);
} catch (Exception exception) {
Log.e("Mqtt", "subscribe error", exception);
}
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Log.e("Mqtt", "Connection onFailure ", exception);
}
});
} catch (Exception exception) {
Log.e("Mqtt", "error " + exception);
}
}
messageArrived
callback – hardillb