Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shun1249844726 opened this issue Nov 15, 2017 · 1 comment

Comments

@shun1249844726
Copy link

shun1249844726 commented Nov 15, 2017

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 shun1249844726 changed the title subscribe subscribe have no call back when the message arrived when i use this method "public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners)" Nov 15, 2017
Governa pushed a commit to Governa/paho.mqtt.android that referenced this issue Oct 5, 2019
Returning null causes problems with all subscribes that receive `IMqttMessageListener` as parameter.
Governa pushed a commit to Governa/paho.mqtt.android that referenced this issue Oct 5, 2019
Always returning null breaks the contract set in the function signature
and documentation.

This affects all subscribes that receive `IMqttMessageListener` as parameter.
Governa pushed a commit to Governa/paho.mqtt.android that referenced this issue Oct 5, 2019
Always returning null breaks the contract set in the function signature
and documentation.

This affects all subscribes that receive `IMqttMessageListener` as parameter.

Signed-off-by: Fernando Governatore <affqlixo+eclipse@gmail.com>
Governa pushed a commit to Governa/paho.mqtt.android that referenced this issue Oct 10, 2019
  On subscribe, a failure would be reported but onSuccess would never be
called. The reason was not passing the IMqttActionListener forward to
MqttClient.
Governa pushed a commit to Governa/paho.mqtt.android that referenced this issue Oct 10, 2019
  On subscribe, a failure would be reported but onSuccess would never be
called. The reason was not passing the IMqttActionListener forward to
MqttClient.

Signed-off-by: Fernando Governatore <affqlixo+eclipse@gmail.com>
hannesa2 referenced this issue in hannesa2/paho.mqtt.android Nov 15, 2020
Always returning null breaks the contract set in the function signature
and documentation.

This affects all subscribes that receive `IMqttMessageListener` as parameter.

Signed-off-by: Fernando Governatore <affqlixo+eclipse@gmail.com>

Should pass IMqttActionListener on subscribe (#262)

  On subscribe, a failure would be reported but onSuccess would never be
called. The reason was not passing the IMqttActionListener forward to
MqttClient.

Signed-off-by: Fernando Governatore <affqlixo+eclipse@gmail.com>
@ididdidi
Copy link

ididdidi commented Mar 9, 2021

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants