Another way to have fun during confinement.
Get to know the Eclipse Paho MQTT library better, by writing two simple client programs which do the following:
- The
pinger
publishes a "ping" message to the topic "ping-ask" on a broker. - This "ping" is received by a listening
ponger
that responds with "pong" on another topic called "pong-response". - The
pinger
receives the "pong" response and rejoices much.
So each program:
- subscribes to a certain topic
- publishes on another one
As an objective, the Quality of Service we strive for is 2.
For additional fun, each program must exist in two versions: synchronous and asynchronous.
Let's use mosquitto's test server as a broker.
I made an extensive use of the examples provided by the Paho MQTT library. Some of this code is weird, though.
// examples/sync_consume.rs
if let Some((server_uri, ver, session_present)) = rsp.connect_response() { ... }
I couldn't find this connect_response()
function anywhere in the library.
Open two terminals in the project directory, and run separately:
cargo run --bin sync_pong
and
cargo run --bin sync_ping
Be sure to launch sync_pong
first, otherwise it won't catch the single message that
sync_ping
sends immediatly when starting.
Same with
cargo run --bin async_pong
and
cargo run --bin async_ping