Comments (3)
You can't really check that specifically, but the client will attempt to resend the message in case no PUBACK is received based on the configured timeout in the ConnectionSettings
.
However, for QoS > 0 you need to run $client->loop()
after publishing the message. You can use the second and third parameter to tune your publishing:
$client->loop(allowSleep: true, exitWhenQueuesEmpty: true, queueWaitLimit: 10);
This will exit the loop immediately when PUBACK is received, but it will retry up to 10 seconds. If the message could not be delivered within 10 seconds, it will exit anyway. See MqttClient::loop()
for details.
A more complete example would be:
$connectionSettings = (new ConnectionSettings())
->setResendTimeout(3); // Resend messages every 3 seconds
$client = new MqttClient($server, $port, $clientId);
$client->connect($connectionSettings);
$client->publish('foo/bar/baz', 'Hello world!', MqttClient::QOS_AT_LEAST_ONCE);
$client->loop(allowSleep: true, exitWhenQueuesEmpty: true, queueWaitLimit: 10);
This will attempt to resend the message every 3 seconds for up to 10 seconds (i.e. 4 attempts).
You can also omit the queueWaitLimit
, then the client will retry forever. That, however, can cause deadlocks as you might guess.
from client-examples.
Thanks for reply.
Right, what I have to do is to display a message saying: data is syncing with broker
to the end user when I publish a new message and when PUBACK is confirmed then I need to swap the message to data has been synced successfully
Is there a way to check if PUBACK was confirmed or at least that an error has ocurred? just so I can inject my logic into there?
I am currently using: $client->registerMessageReceivedEventHandler($handler);
and look for same $topic
to be returned. Would this even work?
from client-examples.
There is no way to check the transmission result or status of individual messages. So the only way you can know for sure that a queued message (or all queued messages) was successfully sent to the broker is by looping until the loop exits by itself:
$client->loop(allowSleep: true);
However, you should note that this only tells you whether the message was sent to the broker successfully, but not if any of the subscribers actually received the message. If you, for example, want to push a command to an individual client indirectly via an MQTT broker, the client should acknowledge the command on a separate topic. It's called the RPC pattern.
from client-examples.
Related Issues (6)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from client-examples.