c++mqttlibmosquittopahocpp

MQTT C++ client


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)?


Solution

  • 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.