hivemq-mqtt-client icon indicating copy to clipboard operation
hivemq-mqtt-client copied to clipboard

Publish and wait for response message

Open eos1d3 opened this issue 2 years ago • 1 comments

Checklist

  • [x ] I've searched the project's issues.
  • [x ] I've searched the project's discussions.

❓ Question

I am using Mqtt5AsyncClient, after publishing a message, is it possible to wait for a response message in publishWith statement?

For example, I am using the following codes:

client.publishWith()
                .topic(DEVICE_UPDATE_TOPIC)
                .payload(payload)
                .responseTopic(APP_RESPONSE_TOPIC)
                .qos(MqttQos.AT_LEAST_ONCE)
                .send()
                .whenComplete((publish, throwable) -> {
                    if (throwable != null)
                        mainActivity.updateDeviceInfoError();
                }).;

Or I have to write some codes inside whenComplete and wait for response message or wait for timeout if no message is received?

📎 Additional context

eos1d3 avatar Jun 09 '23 03:06 eos1d3

Hi @eos1d3 - we have a full request/response example here. That should point out the right pattern to use - Let me know if this helps.

pglombardo avatar Jun 12 '23 07:06 pglombardo

Hi @eos1d3 - since we haven't heard back I'll close out this issue but if anything remains, let us know. We'd be more than happy to help out!

pglombardo avatar Mar 05 '24 12:03 pglombardo