You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
Auto assigned subscription identifier isn't sent to the broker
The existence of the subscription identifier when subscribing using the MQTT5 client is
Using the wrong list to check for it's existence
Not setting the auto-incremented value on the subscription options for the subscribe request
A simple demo that demonstrates the issue:
import com.hivemq.client.mqtt.datatypes.MqttQos;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.eclipse.paho.mqttv5.client.IMqttToken;
import org.eclipse.paho.mqttv5.client.MqttAsyncClient;
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;
import org.eclipse.paho.mqttv5.common.MqttSubscription;
import org.eclipse.paho.mqttv5.common.packet.MqttProperties;
public class TestPaho
{
public static void main(String[] args) throws InterruptedException, MqttException
{
MqttAsyncClient serverClient = new MqttAsyncClient("tcp://localhost:1883", "myServer");
MqttAsyncClient deviceClient = new MqttAsyncClient("tcp://localhost:1883", "myDevice");
serverClient.connect().waitForCompletion();
deviceClient.connect().waitForCompletion();
System.out.println("Connected");
CountDownLatch receivedLatch = new CountDownLatch(4);
MqttProperties subProperties1 = new MqttProperties();
subProperties1.setSubscriptionIdentifiers(List.of(0)); // Bug in paho? This is for publish but subscribe requires it
# subProperties1.setSubscriptionIdentifier(1);
serverClient.subscribe(new MqttSubscription("#", MqttQos.AT_LEAST_ONCE.getCode()), null, null, (topic, message) ->
{
System.out.println("# - Received message");
receivedLatch.countDown();
}, subProperties1);
MqttProperties subProperties2 = new MqttProperties();
subProperties2.setSubscriptionIdentifiers(List.of(0));
# subProperties2.setSubscriptionIdentifier(2);
serverClient.subscribe(new MqttSubscription("A", MqttQos.AT_LEAST_ONCE.getCode()), null, null, (topic, message) ->
{
System.out.println("A - Received message");
receivedLatch.countDown();
}, subProperties2);
System.out.println("A - Sending");
deviceClient.publish("A", new MqttMessage("1".getBytes(), MqttQos.AT_LEAST_ONCE.getCode(), false, new MqttProperties()))
.waitForCompletion();
System.out.println("A - Sent");
receivedLatch.await();
deviceClient.close();
serverClient.close();
}
}
Any user of the API needs to use MqttProperties#setSubscriptionIdentifier regardless of Automatic Subscription Identifier Assignment.
The property it should be checking within a subscribe is the MqttProperties#getSubscriptionIdentifier. Not the list.
The doc states:
/**
* Subscription Identifiers. (Publish Only)
*
* <p>
* The Subscription Identifiers are associated with any subscription created or
* modified as the result of a SUBSCRIBE packet. If a subscription was made with
* a Subscription Identifier, then any incoming messages that match that
* subscription will contain the associated subscription identifier, if the
* incoming message matches multiple subscriptions made by the same client, then
* it will contain a list of all associated subscription identifiers. This
* property is ONLY for PUBLISH packets. For a Subscription Identifier sent in a
* SUBSCRIBE packet, see {@link MqttProperties#getSubscriptionIdentifier()}
* </p>
*
* @return A {@link List} of Subscription Identifiers.
*/
public List<Integer> getSubscriptionIdentifiers() {
return publishSubscriptionIdentifiers;
}
...
/**
* Subscription Identifier. (Subscribe Only)
*
* <p>
* The Subscription identifier field can be set on a SUBSCRIBE packet and will
* be returned with any incoming PUBLISH packets that match the associated
* subscription. This property is ONLY for SUBSCRIBE packets. For Subscription
* Identifier(s) sent in a PUBLISH packet, see
* {@link MqttProperties#getSubscriptionIdentifiers()}
* </p>
*
* @return The Subscription Identifier.
*/
public Integer getSubscriptionIdentifier() {
return subscribeSubscriptionIdentifier;
}
Auto assigned subscription identifier isn't sent to the broker
The existence of the subscription identifier when subscribing using the MQTT5 client is
A simple demo that demonstrates the issue:
Any user of the API needs to use MqttProperties#setSubscriptionIdentifier regardless of
Automatic Subscription Identifier Assignment
.The property it should be checking within a subscribe is the MqttProperties#getSubscriptionIdentifier. Not the list.
The doc states:
The correct property asside, the newly chosen subId is used internally https://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/MqttAsyncClient.java#L1308 but never set when sending the SUBSCRIBE message https://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.mqttv5.client/src/main/java/org/eclipse/paho/mqttv5/client/MqttAsyncClient.java#L1314
The text was updated successfully, but these errors were encountered: