Skip to content

Getting familiar with the Eclipse Paho MQTT library, in Rust

Notifications You must be signed in to change notification settings

Keksoj/mqtt_ping_pong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT ping-pong

Another way to have fun during confinement.

this is it

Objectives

Get to know the Eclipse Paho MQTT library better, by writing two simple client programs which do the following:

  1. The pinger publishes a "ping" message to the topic "ping-ask" on a broker.
  2. This "ping" is received by a listening ponger that responds with "pong" on another topic called "pong-response".
  3. 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.

Ressources

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.

Run the synchronous ping-pong

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.

Run the asynchronous ping-pong

Same with

cargo run --bin async_pong

and

cargo run --bin async_ping

About

Getting familiar with the Eclipse Paho MQTT library, in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages