hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
870 stars 161 forks source link

How to subscribe with a custom subscription identifier? #611

Closed andsel closed 10 months ago

andsel commented 10 months ago

Checklist

❓ Question

How can I [...]? I don't know if it's possible and how set subscription identifier during the subscribe

Is it possible to [...]? Set a custom subscription identifier when sending a SUBSCRIBE message to the broker

📎 Additional context

subscriber.subscribeWith()
            .topicFilter("/metric/temperature/#")
// --> how to configure here the subscription identifier?
            .send();
pglombardo commented 10 months ago

Hi @andsel - there is no API for this - this client has been built to manage subscription identifiers automatically internally when it's supported by the broker.

Not all brokers support subscription identifiers (HiveMQ does) so support has to be checked in the CONNACK connect response.

Managing IDs (and their re-use) can be cumbersome when dealing with a lot of subscriptions.

What's your use case/problem to solve? Maybe we can find an alternative solution...

andsel commented 10 months ago

Hi @pglombardo I'm writing the MQTT 5 support in Moquette broker and using HiveMQ client to create integration tests, in particular I was writing the test to proof the subscription identifier so I was wondering how to value that mqtt property in the the subscribe. You answered my question, when I'll enable the subscription identifier capability in CONNACK I'll start seeing the subscriptions using it.

Thanks! 👍

pglombardo commented 10 months ago

Excellent - let me know if you have any issues.