eclipse-paho / paho.mqtt.android

MQTT Android
Other
2.94k stars 892 forks source link

Receive null after subscrible with IMqttMessageListener #330

Open PhanVanLinh opened 5 years ago

PhanVanLinh commented 5 years ago

dependency

implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
implementation('org.eclipse.paho:org.eclipse.paho.android.service:1.1.1') {
        exclude module: 'support-v4'
}

Problem

val subToken = mqttClient.subscribe(topic, 1, object:IMqttMessageListener{
    override fun messageArrived(topic: String?, message: MqttMessage?) {
        L.d("messageArrived")
    }
})
// subToken = null here
val subToken = mqttClient.subscribe(topic, 1)
// subToken NOT null here
roberthartman commented 4 years ago

I don't know if the token being null is the problem or not, but I observe the same thing, and also observe that message listener is never called when messages arrive.

val token = client.subscribe(topic, 0, userContext, actionListener, messageListener)
if (token == null) {
    logger.error("token is null")
}