SmartsquareGmbH / mqtt-starter

HiveMQ Spring Boot Starter
MIT License
15 stars 5 forks source link

How to get Optional<MqttTopic> response topic in @MqttSubscribe annotation #12

Closed tksarul closed 5 months ago

tksarul commented 7 months ago

I would like to get response topic (may be optional) in subscription. like below

@MqttSubscribe(topic = "t/a/1", qos = EXACTLY_ONCE) public void subscribeAdRequestTopic(String payload, MqttTopic topic, Optional responseTopic) { log.debug("paylaod: {} in {}, and response to ", payload, topic, responseTopic); }

rubengees commented 7 months ago

Hi!

The responseTopic can not be directly specified in the method signature. Instead, with the latest 0.16.0 release you could inject the Mqtt5Publish and go from there:

@MqttSubscribe(topic = "t/a/1", qos = EXACTLY_ONCE)
public void subscribeAdRequestTopic(Mqtt5Publish message, String payload, MqttTopic topic) {
    Optional<MqttTopic> responseTopic = message.getResponseTopic();

    log.debug("paylaod: {} in {}, and response to ", payload, topic, responseTopic);
}

Hope that helps :slightly_smiling_face:

tksarul commented 5 months ago

Thanks, This helps lot.