NanoMQ is an MQTT message engine + multi-protocol message bus for edge computing. It supports MQTT protocol and different common bus protocols at the edge such as ZeroMQ and Nanomsg, and integrates broker and brokerless message modes to facilitate the creation of IoT edge computing applications.

Community site address: https://nanomq.io/zh

GitHub repository: https://github.com/emqx/nanomq

The NanoMQ project has maintained a steady iterative speed of one minor version + one important new function per month, and v0.8.0 was officially released at the end of May (download link: https://github.com/emqx/nanomq/releases/tag/0.8 .0 ). This time we bring you 2 important feature updates: Event WebHook and a connection authentication interface that can be integrated with third-party HTTP APIs. At the same time, an HTTP API for viewing the topic tree structure has been added, and various performance optimizations and bug fixes are also being continuously updated.

Efficient and easy-to-use edge WebHook system

WebHook is a feature of EMQX that is deeply loved by the majority of open source users. NanoMQ has also launched the same feature in response to community calls to facilitate users to integrate with third-party edge computing applications.

NanoMQ's WebHook system is in the same line as EMQX, and adopts the same style of configuration. The default search path for the configuration file of Webhook is /etc/nanomq_web_hook.conf, or you can start by reading the configuration file by specifying the path on the command line. For specific configuration items, see NanoMQ Docs: https://nanomq.io/docs/zh/latest/web-hook.html#Configuration Items.

 web.hook.enable=true
## 格式示例
web.hook.rule.<Event>.<Number>=<Rule>

After enabling the WebHook function in the settings, you can configure the triggering rules according to your needs. If you need to forward the client online and offline events and all messages matching the "webhook/msg/#" wildcard topic to the corresponding HTTP API, the configuration method as follows:

Trigger rule configuration

Trigger rules can be configured in etc/nanomq_web_hook.conf, and the configuration format is as follows:

 ## 示例
web.hook.enable=true
web.hook.url=http://127.0.0.1:8888
web.hook.headers.content-type=application/json
web.hook.body.encoding_of_payload_field=plain
web.hook.pool_size=32
web.hook.rule.client.connack.1={"action": "on_client_connack"}
web.hook.rule.client.disconnected.1={"action": "on_client_disconnected"}
web.hook.rule.message.publish.1={"action": "on_message_publish", "topic": "webhook/msg/#"}

This setting allows NanoMQ to automatically capture and spit out the data of the client's online and offline and message publishing to the corresponding HTTP API. An example of the data format of the current HTTP request is as follows:

 ## HTTP json格式示例
Connack(客户端连接成功事件):
{
  "proto_ver": 4,
  "keepalive": 60,
  "conn_ack": "success",
  "username": "undefined",
  "clientid": "nanomq-6ecb0b61",
  "action": "client_connack"
}

Publish(消息发布):
{
  "ts": 1650609267000,
  "topic": "webhook/msg/123",
  "retain": false,
  "qos": 0,
  "action": "message_publish",
  "from_username": "undefined",
  "from_client_id": "nanomq-6ecb0b61",
  "payload": "hello"
}

Disconnect(客户端连接断开事件):
{
  "reason": "normal",
  "username": "undefined",
  "clientid": "nanomq-6ecb0b61",
  "action": "client_disconnected"
}

Currently NanoMQ's WebHook system supports the following events:

name illustrate execution time
client.connack MQTT client connected successfully When the server is ready to send a connection response message
client.disconnected MQTT client connection disconnected The client connection layer is preparing to close
message.publish MQTT message publishing Before the server publishes (routes) the message

If you need more news events, please submit a function application issue on the Github page of the NanoMQ project, and we will arrange to add it as soon as possible.

It should be emphasized that the WebHook function of NanoMQ is a fully asynchronous operation. All matching event messages will enter an independent dedicated thread for processing through an efficient internal IPC channel, which is isolated from the Broker function and will not block the normal operation of the original server. The flow of news is very efficient and reliable.

NanoMQ WebHook

For the specific configuration information and methods of WebHook, as well as how to tune, please look forward to the NanoMQ series tutorial articles in the future.

HTTP connection authentication API

HTTP connection authentication is another commonly used integration function, which can be easily integrated with a third-party authentication server to complete client connection request verification. Another common open source project Mosquitto's similar plug-in has been abandoned and no longer maintained. This function of NanoMQ fills this gap, and also maintains the same function and configuration style as EMQX, which is convenient for users to get started.

Authentication rule configuration

The configuration file of the Authentication HTTP API interface is read in the same way as other configuration files of NanoMQ. The configuration items included are:

 ## 是否开启HTTP Auth 插件
## Value: true | false
auth.http.enable = true

## Auth请求的目标HTTP URL
auth.http.auth_req.url = http://127.0.0.1:80/mqtt/auth

## HTTP Auth Request 请求方式
## Value: post | get
auth.http.auth_req.method = post

## HTTP Request Headers for Auth Request
auth.http.auth_req.headers.content_type = application/x-www-form-urlencoded

## Parameters used to construct the request body or query string parameters
auth.http.auth_req.params = clientid=%c,username=%u,password=%P

After the configuration is complete, NanoMQ will request the corresponding HTTP URL for the information of the client Connect package according to the request format set by the configuration. And according to the return code to determine whether to allow the client to connect successfully (Code 200 indicates success). For more detailed configuration methods, please refer to the official website configuration document https://nanomq.io/docs/en/latest/config-description.html#parameter-description .

Other function optimizations and bug fixes

In addition, NanoMQ 0.8.0 has the following updates and optimizations:

  1. Correct the timestamp field in the client log-off and log-off time message to be UNIX standard timestamp, previously it was the start timer.
  2. Modified the usage of the NanoMQ command line tool, removing the restriction that "start/stop" must be used by default.
  3. Added documentation for ZeroMQ broker message gateway.
  4. Fixed a lock contention issue when bridged connections were frequently closed by the remote end.
  5. Fixed the data race problem caused by the sudden port of the Sub client when the client published a large number of messages and caused a backlog.
  6. No longer defaults to UTF-8 checking of last wish message content, only if requested by the client.
  7. Fixed a crash when using Retain As Published messages if the message property was empty.

coming soon

NanoMQ will officially release the rules engine next month and incorporate a new database as an option for full persistence of edge data. This feature is currently in the Demo stage and is available in the latest master branch. Users can compile and install by themselves, welcome to try: https://github.com/emqx/nanomq/ .

NanoSDK will release the RC version of MQTT over QUIC next month, which is the industry's first C-based MQTT SDK that fully supports MQTT 3.1.1 and QUIC functions, so stay tuned.

Copyright statement: This article is original by EMQ, please indicate the source when reprinting.

Original link: https://www.emqx.com/zh/blog/nanomq-newsletter-202205


EMQX
336 声望438 粉丝

EMQ(杭州映云科技有限公司)是一家开源物联网数据基础设施软件供应商,交付全球领先的开源 MQTT 消息服务器和流处理数据库,提供基于云原生+边缘计算技术的一站式解决方案,实现企业云边端实时数据连接、移动、...