Skip to content
New issue

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

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

Already on GitHub? # to your account

Shared subscription not working correctly #827

Open
1 of 3 tasks
escoand opened this issue Sep 4, 2020 · 7 comments
Open
1 of 3 tasks

Shared subscription not working correctly #827

escoand opened this issue Sep 4, 2020 · 7 comments

Comments

@escoand
Copy link

escoand commented Sep 4, 2020

  • Bug exists Release Version 1.2.5 ( Master Branch)
  • Bug exists in MQTTv3 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)
  • Bug exists in MQTTv5 Client on Snapshot Version 1.2.6-SNAPSHOT (Develop Branch)

When receiving a message on a shared subscription the registered IMqttMessageListener.messageArrived( isn't called. Instead the registered MqttCallback.messageArrived( is called. Workaround could be to subscribe as shared and non-shared subscription.

Reproduce:

  1. subscribe to topic $share/group1/any/topic
  2. send message to to topic any/topic
@em14Vito
Copy link

in V1.2.4, bug also exist. Thanks you solution. Use MqttCallback instead implement MqttCallback it work! @escoand 👍

@Miggets7
Copy link

This is also the case when using wildcard in topics. When deliverMessage is called in CommsCallback, it validates the topic and doesn't allow wildcards in MqttTopic.isMatched. In the end it throws IllegalArgumentException("The topic name MUST NOT contain any wildcard characters (#+)")

@SomberOfShadow
Copy link

in V1.2.4, bug also exist. Thank

did you want to say "Use MqttCallback instead implement IMqttMessageListener" ?

@magx2
Copy link

magx2 commented Nov 22, 2022

I can also confirm that in version 1.2.5 this code will not work:

mqttClient.subscribe("$shared/group/some_topic/#", 1, (topic, message) -> System.out.println(topic));

instead it's required to use callbacks:

mqttClient.subscribe("$shared/group/some_topic/#", 1);
mqttClient.setCallback(new MqttCallback() {
    @Override
    public void connectionLost(final Throwable cause) {

    }

    @Override
    public void messageArrived(final String topic, final MqttMessage message) throws Exception {
        System.out.println(topic);
    }

    @Override
    public void deliveryComplete(final IMqttDeliveryToken token) {

    }
});

@wilx
Copy link

wilx commented Feb 1, 2024

I am still hitting this issue. Paho is the only supported MQTT client with Spring Integration and this makes it a lot less useful than it could be.

@iiliev2
Copy link

iiliev2 commented Feb 1, 2024

It looks like either

  • org.eclipse.paho.mqttv5.client.internal.CommsCallback#setMessageListener must be changed so that the callback is mapped against the topic filter without the shared sub prefix(if there is one) ~ $share/<share-name>/, or
  • org.eclipse.paho.mqttv5.common.util.MqttTopicValidator#isMatched must be updated to be able to match when there is a shared sub prefix

@aditya-pathak-dc
Copy link

aditya-pathak-dc commented Jun 11, 2024

@wilx I am using 6.3.0 version of spring-mqtt-integration, but still facing the same issue. Unable to receive message on shared topics.
Here are the details: https://stackoverflow.com/questions/78605910/spring-mqtt-integration-shared-subscritopn-is-not-working

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

No branches or pull requests

8 participants