eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 883 forks source link

Shared subscription not working correctly #827

Open escoand opened 4 years ago

escoand commented 4 years ago

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 commented 3 years ago

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

Miggets7 commented 3 years ago

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 commented 2 years ago

in V1.2.4, bug also exist. Thank

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

magx2 commented 1 year ago

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 commented 7 months ago

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 commented 7 months ago

It looks like either

aditya-pathak-dc commented 3 months ago

@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