Giter Site home page Giter Site logo

githubworksonline / nanosdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emqx/nanosdk

0.0 0.0 0.0 9.18 MB

NanoSDK - MQTT 5.0-compliant SDK with QUIC support in NNG flavor

Home Page: https://nanomq.io

License: MIT License

Shell 0.12% C++ 0.50% C 98.65% Go 0.11% CMake 0.63%

nanosdk's Introduction

Discord Twitter YouTube Community Build Status

NanoSDK C Client Library for the MQTT Protocol

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.

Introduction & Rationale

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.

Advantages

Compared with other popular MQTT 3.1.1 SDK, NanoSDK has the following advantages:

  1. Fully asynchronous I/O and good SMP support NanoSDK based on NNG's asynchronous I/O, we implement the Actor-like programming model in C language. And managing to distribute the computation load among multiple CPU cores averagely.
  2. High compatibility and portability Inheriting the compatibility and easy portability of NNG, NanoSDK only relies on the native POSIX standard API and is friendly to various distributions of Linux. It can be migrated to any hardware and operating system platform easily.
  3. Support multiple API styles The programming style of the NNG framework comes with a high learning cost, and users need to have a deep understanding of the concept of AIO and Context. Therefore, we also prepared a traditional callback registration mechanism for users who are accustomed to using Paho and Mosquitto SDK. This not only reduces the programming difficulty but also reserves the advantages of NNG.
  4. High throughput & Low latency In NanoMQ's test report, its performance advantages of powerful high throughput and low latency have been reflected, and the direct successor of NanoMQ - the SDK also has excellent performance. It is cost-effective in terms of resources consumption. Unlike the traditional MQTT SDK which has only 1-2 threads, NanoSDK can make full use of system hardware resources to provide higher consumption throughput. In most IoT solutions based on EMQX, the backend service’s insufficient consuming capability always results in message congestion, which has always been a problem for open source developers. Especially for QoS 1/2 messages, most SDKs reply Ack for QoS 1/2 messages synchronously. NanoSDK provides asynchronous Ack capability under the premise of ensuring the QoS message sequence and message retransmission mechanism, which greatly improves the throughput and consumption capacity of QoS 1/2.

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)

Information About MQTT

Libraries

The NanoSDK C client comprises four variant libraries, shared or static:

  • nng/demo/mqtt- simple mqtt client
  • nng/demo/mqtt_async - asynchronous MQTT client & command-linewith SSL/TLS (MQTTAsync)
  • nng/demo/mqttv5- simple mqttv5 client with async API
  • nng/demo/quic- simple MQTT over QUIC demo (Attention: MsQUIC needs to be installed)

API Documentation

The API documentation is provided in Asciidoc format in the docs/man subdirectory The docs/man/libnng.3.adoc#,libnng(3) page is a good starting point.

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.

Building with CMake

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

nanosdk's People

Contributors

a-j-k avatar alvin1221 avatar awakecoding avatar codypiersall avatar dehorsley avatar gdamore avatar jake-ruyi avatar janjaapbos avatar jaylinyu avatar khorben avatar l0pital avatar liamstask avatar lilywangl avatar lkesteloot avatar manuelgustavo avatar mbush00 avatar mjgigli avatar mzipay avatar neachdainn avatar phreed avatar qxsoftware avatar realsense3d avatar robiwano avatar stargazerwayne avatar suntonix avatar unspecd avatar urkle avatar voutilad avatar wanghaemq avatar xinyi-xs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.