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
832 stars 153 forks source link

Publish and wait for response message #577

Closed eos1d3 closed 4 months ago

eos1d3 commented 1 year ago

Checklist

❓ 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

pglombardo commented 1 year ago

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

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!