15

I'd like to implement an MQTT client functionality in C++ (it needs to be thread-safe, and be able to subscribe to topics and also publish, but no broker functionality is needed).

I was considering Paho MQTT by Eclipse. Here is their download page.

I find there that they don't have MQTT5.0 support.

On their github however: there is C++ wrapper which at version 1.1 states MQTTv5.0 support.

Then I have found this question: Mosquitto vs eclipse paho client library, where the conclusion was:

to use libmosquitto with libmosquittopp wrapper

I checked libmosquittopp.h: all functions are marked as deprecated, so I don't think it can be the right way as of now.

Why is libmosquittopp deprecated? Because

The wrapper came about by an external request and at the time it was created there were no other C++ solutions for MQTT. This has changed in the past years and this wrapper provides no benefit over true C++ libraries or using the pure C libmosquitto.

So, is Paho now considered the right direction for using MQTT within C++?

Or I shall just use the pure C library by Mosquitto?

Or, anything else (except writing it from 0)?

3 Answers 3

19

The Paho C++ library does support MQTT v5, and is thread safe. You can publish and subscribe from multiple threads with a single client connection.

Some of the Eclipse web pages need to be updated with the latest features. The GitHub repos tend to have the latest information.

The Paho C++ lib just wraps the Paho C library, but provides an asynchronous, futures-style API, and provides memory management via shared pointers.

7

If you use Boost.asio, then this project is the right choice.

https://github.com/redboltz/mqtt_cpp

It's native C++, no wrapper-around-C, and supports both v3.1.1 and v5.

6

As of November 2023, there is a new kid on the block, Async.MQTT5:

https://github.com/mireo/async-mqtt5

It is also built on top of Boost.Asio, but with remarkably robust, clean and concise code. From the official documentation:

Async.MQTT5 is a professional, industrial-grade C++17 client built on Boost.Asio. This client is designed for publishing or receiving messages from an MQTT 5.0 compatible broker. Async.MQTT5 represents a comprehensive implementation of the MQTT 5.0 protocol standard, offering full support for publishing or receiving messages with QoS 0, 1, and 2.

Our clear intention is to include the Async.MQTT5 library into Boost. We are actively working on it.

Disclaimer: I work in Mireo, a company that open-sourced this MQTT client.

Not the answer you're looking for? Browse other questions tagged or ask your own question.