This repository contains the source code for the NanoSDK MQTT C client library.
This project is a wrapping of the nanomsg-NNG(https://github.com/nanomsg/nng) nanomsg known as https://github.com/nanomsg/nanomsg[libnanomsg], and adds significant new capabilities like MQTT & QUIC while retaining compatibility with the original Scalability Protocols.
NOTE: In honor of NNG & Garrett(Creator & Maintainer), they are the cornerstone of NanoSDK. We respect all his contributions to the Open-Source world. And We create this repository only for tracking Issues/Discussions and fast-paced development while the MQTT support is missing in upstream.
NanoSDK is an open-source project jointly developed by EMQ and NNG. NanoSDK as a repository, it is maintained independently as the NNG version of NanoMQ (https://github.com/emqx/nanomq). At present, its master branch is a special version developed and optimized for MQTT workload and maintained independently, from which we have submitted several valuable PRs and Issues for NNG. Therefore, to make NanoMQ compatible with NNG's SP protocol, we are committed to adding MQTT 3.1.1/5.0 protocol support for NNG at here. So that the two kinds of protocols(MQTT and SP) can be used together with NanoSDK. This is also in accordance with the RoadMap direction previously formulated by NanoMQ team. According to the technical goals previously formulated with the NNG project maintainer - Garrett at the jointly open-source cooperation meeting, NNG will support ZeroMQ and MQTT 3.1.1/5.0 in the future. Before this really happens, this project will be maintained independently. The internal design of NanoSDK honors the programming style of the NNG framework and is compatible with the original SP protocol of NNG. At the same time, it does not affect the other features like HTTP/Websocket/TLS.
Compared with other popular MQTT 3.1.1 SDK, NanoSDK has the following advantages:
Inherited from NNG, NanoSDK is a performant & higly portable SDK. Which enable users create client application with high throughput.
This code builds libraries which enable applications to connect to an MQTT broker to publish messages, and to subscribe to topics and receive published messages.
For MQTT broker introduction, please refer to EMQX (https://github.com/emqx/emqx)
The NanoSDK C client comprises four variant libraries, shared or static:
The API documentation is provided in Asciidoc format in the
docs/man
subdirectory
The <<docs/man/nng.7.adoc#,nng(7)>> page provides a conceptual overview and links to
manuals for various patterns.
The <<docs/man/libnng.3.adoc#,libnng(3)>> page is a good starting point for the API reference.
In addition, many users would like to add self-defined behavior in the callback of online and offline. Therefore, we modified the callback method of connection and disconnection to allow users to perform blocking and waiting operations in the callback without affecting the MQTT connection & pradigm itself, so as to improve the flexibility of NanoSDK. However, it should be noted that this will consume the number of threads inside the NanoSDK. If the taskq thread is exhausted, it will still affect the operation of the entire client. Please use it cautiously.
git clone https://github.com/emqx/NanoSDK ; cd NanoSDK
git submodule update --init --recursive
mkdir build && cd build
cmake -G Ninja ..
ninja
To enable Debug + ASAN
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF ..
To enable MQTT over QUIC feature
cmake -G Ninja -DBUILD_SHARED_LIBS=OFF -DNNG_ENABLE_QUIC=ON ..