The __MQTT__ protocol is widely utilised for communication in various real-world scenarios,
primarily serving as a reliable communication protocol for data transfer to and from IoT devices.
While the MQTT protocol itself is relatively straightforward, integrating it into an application can be complex,
especially due to the challenging implementation of message retransmission after a disconnect/reconnect sequence.
The aim of __Self__ is to provide a very simple asynchronous C++ interface for application developers.
The internal client's implementation manages network and MQTT protocol details.
Notably, the client does not expose connect functions (nor asynchronous connect functions);
instead, network connectivity, MQTT handshake, and message retransmission are automatically handled within the client.
The __Self__ interface aligns seamlessly with the __Asio__ asynchronous model.
The client's asynchronous functions are compatible with all completion tokens supported by __Asio__.
[heading Features]
__Self__ is a C++ MQTT Client library designed with the core belief that users should focus solely on their application logic, not the network complexities. [br]
The library attempts to embody this belief with a range of key features designed to elevate the development experience:
* [*Complete TCP, TLS/SLL, and WebSocket support]
* [*User-focused simplicity]: Providing an interface that is as simple as possible without compromising functionality.
* [*Prioritized efficiency]: Utilising network and memory resources as efficiently as possible.
* [*Minimal memory footprint]: Ensuring optimal performance in resource-constrained environments typical of IoT devices.
* [*Automatic reconnect]: Automatically attempt to re-establish a connection in the event of a disconnection.
* [*Fully Boost.Asio compliant]: The interfaces and implementation strategies are built upon the foundations of __Asio__. [br]
__Asio__ and __Beast__ users will have no issues understanding and integrating __Self__. [br]
Furthermore, __Self__ integrates well with any other library within the Boost.Asio ecosystem.
* [*Custom allocators]: Support for custom allocators allows extra flexibility and control over the memory resources. [br]
__Self__ will use allocators associated with handlers from asynchronous functions to create instances of objects needed in the library implementation.
* [*Per-Operation Cancellation]: All asynchronous operations support individual, targeted cancellation as per Asio’s __ASIO_PER_OP_CANCELLATION__.
* [*Completion Token]: All asynchronous functions support __CompletionToken__, allowing for versatile usage with callbacks, coroutines, futures, and more.
* [*Full implementation of MQTT 5.0 specification]
* [*Support for QoS 0, QoS 1, and QoS 2]
* [*Custom authentication]: __Self__ defines an interface for your own custom authenticators to perform Enhanced Authentication.
* [*High availability]: __Self__ supports listing multiple Brokers within the same cluster to which the Client can connect. [br]
In the event of a connection failure with one Broker, the Client switches to the next in the list.
* [*Offline buffering]: While offline, it automatically buffers all the packets to send when the connection is re-established.
[heading Example]
The following example illustrates a simple scenario of configuring a Client and publishing an Application Message.
[!c++]
#include <iostream>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <async_mqtt5.hpp>
int main() {
boost::asio::io_context ioc;
using client_type = async_mqtt5::mqtt_client<boost::asio::ip::tcp::socket>;