paho.mqtt.android icon indicating copy to clipboard operation
paho.mqtt.android copied to clipboard

subscribe have no call back when the message arrived when i use this method "public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners)"

Open shun1249844726 opened this issue 8 years ago • 1 comments

I use

    compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.1'
    compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

I found a problem
why

	public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback, IMqttMessageListener[] messageListeners) throws MqttException {
		IMqttToken token = new MqttTokenAndroid(this, userContext, callback, topicFilters);
		String activityToken = storeToken(token);
		mqttService.subscribe(clientHandle, topicFilters, qos, null, activityToken, messageListeners);

		return null;
	}

this function return null In the source code in "package org.eclipse.paho.android.service;"-“MqttAndroidClient”; It will lead to the calling function will fail for example

            mqttAndroidClient.subscribe(subscriptionTopic, qoss, new IMqttMessageListener[]{new IMqttMessageListener() {
                @Override
                public void messageArrived(String topic, MqttMessage message) throws Exception {
                    System.out.println("arrived:");
                }
            }});

it will not call the "messageArrived" method when the message arrived from server

while the below method will call normally

	@Override
	public void messageArrived(String topic, MqttMessage message) throws Exception {
		try {
			System.out.println("MQTT:message:"+message.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

Console Log output (if available):

shun1249844726 avatar Nov 15 '17 06:11 shun1249844726

implementation 'androidx.legacy:legacy-support-v4:1.0.0' // Required, for Android version 4.x
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

Same problem: MqttAndroidClient, line 1144

public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback, IMqttMessageListener[] messageListeners) throws MqttException {
    IMqttToken token = new MqttTokenAndroid(this, userContext, callback, topicFilters);    
    String activityToken = storeToken(token);
    mqttService.subscribe(clientHandle, topicFilters, qos, null, activityToken, messageListeners);
    return null;
}

0xA5-src avatar Mar 09 '21 11:03 0xA5-src