[{"data":1,"prerenderedAt":357},["ShallowReactive",2],{"blog-post-zh-nanomq-newsletter-202202":3},{"post":4,"translationPath":-1},{"id":5,"title":6,"author":7,"body":8,"cover":341,"coverHeight":342,"coverWidth":343,"date":344,"description":345,"draft":346,"extension":347,"meta":348,"navigation":349,"path":350,"pinned":346,"seo":351,"sitemap":352,"stem":353,"tags":354,"__hash__":356},"blog_zh\u002Fzh\u002Fblog\u002Fnanomq-newsletter-202202.md","NanoMQ Newsletter 2022-02｜0.6.2 支持共享订阅、SDK 优化",null,{"type":9,"value":10,"toc":326},"minimark",[11,21,25,32,37,48,52,58,86,90,93,96,99,134,239,242,250,253,279,283,286,290,293,305,309,312,316,319],[12,13,14,15,20],"p",{},"本月，在隆冬季节和春节假期 NanoMQ-NanoSDK 项目也没有放慢更新的步伐。新发布的 0.6.3 版本中，我们进一步完善了 ",[16,17,19],"a",{"href":18},"\u002Fzh","NanoMQ"," 的命令行工具，为其增加了 TLS 端口支持，同时进一步优化重构了 NanoSDK。",[22,23,24],"h2",{"id":24},"命令行工具",[12,26,27,31],{},[16,28,30],{"href":29},"\u002Fzh\u002Fblog\u002Fnanomq-newsletter-202201","在上个月的 Newsletter 中","我们预告了连接测试工具和压力测试工具。本月其中的连接测试工具已完成：",[33,34,36],"h3",{"id":35},"connection","Connection",[38,39,44],"pre",{"className":40,"code":42,"language":43},[41],"language-text","Usage: nanomq conn { start | stop } \u003Caddr> [\u003Copts>...]\n\n\u003Caddr> must be one or more of:\n  --url \u003Curl>                      The url for mqtt broker ('mqtt-tcp:\u002F\u002Fhost:port' or 'tls+mqtt-tcp:\u002F\u002Fhost:port')\n                                   [default: mqtt-tcp:\u002F\u002F127.0.0.1:1883]\n\n\u003Copts> may be any of:\n  -V, --version \u003Cversion: 3|4|5>   The MQTT version used by the client [default: 4]\n  -n, --parallel               The number of parallel for client [default: 1]\n  -v, --verbose                 Enable verbose mode\n  -u, --user \u003Cuser>                The username for authentication\n  -p, --password \u003Cpassword>        The password for authentication\n  -k, --keepalive \u003Ckeepalive>      A keep alive of the client (in seconds) [default: 60]\n  -i, --interval \u003Cms>              Interval of establishing connection (ms) [default: 10]\n  -C, --count \u003Cnum>                Num of client\n  -q, --qos \u003Cqos>                  Quality of service for the corresponding topic [default: 0]\n  -r, --retain                     The message will be retained [default: false]\n  -c, --clean_session \u003Ctrue|false> Define a clean start for the connection [default: true]\n  --will-qos \u003Cqos>                 Quality of service level for the will message [default: 0]\n  --will-msg \u003Cmessage>             The payload of the will message\n  --will-topic \u003Ctopic>             The topic of the will message\n  --will-retain                    Will message as retained message [default: false]\n  -s, --secure                     Enable TLS\u002FSSL mode\n      --cacert \u003Cfile>              CA certificates file path\n      -E, --cert \u003Cfile>            Certificate file path\n      --key \u003Cfile>                 Private key file path\n      --keypass \u003Ckey password>     Private key password\n","text",[45,46,42],"code",{"__ignoreMap":47},"",[33,49,51],{"id":50},"example","Example",[38,53,56],{"className":54,"code":55,"language":43},[41],"nanomq conn start --url \"mqtt-tcp:\u002F\u002Fbroker.emqx.io:1883\" -C 10000 -i 10 -k 60\n",[45,57,55],{"__ignoreMap":47},[12,59,60,61,67,68,73,74,79,80,85],{},"使用 NanoMQ Conn 工具向 ",[16,62,66],{"href":63,"rel":64},"https:\u002F\u002Fwww.emqx.com\u002Fzh",[65],"nofollow","EMQ"," 提供的",[16,69,72],{"href":70,"rel":71},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fmqtt\u002Fpublic-mqtt5-broker",[65],"公共 MQTT 服务器"," 的 msg 主题每 10ms 创建一个 ",[16,75,78],{"href":76,"rel":77},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fblog\u002Fthe-easiest-guide-to-getting-started-with-mqtt",[65],"MQTT"," 连接。当创建到 10000 个连接时停止。使用这一工具可以测试 ",[16,81,84],{"href":82,"rel":83},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fblog\u002Fthe-ultimate-guide-to-mqtt-broker-comparison",[65],"MQTT Broker"," 的并发连接能力。",[22,87,89],{"id":88},"支持-tls","支持 TLS",[12,91,92],{},"安全问题一直是物联网应用必须考虑的重点。MQTT+TLS 是最广泛使用的链接加密方式。从 0.6.3 版本开始，NanoMQ 能够支持客户端通过 TCP+TLS 或 Websocket+TLS 端口接入，默认端口分别是 8883 和 8084。使用方法如下：",[12,94,95],{},"首先 NanoMQ 的 TLS 支持是默认关闭的，目前 0.6.0 的二进制安装包还未默认开启 TLS 功能。需要用户编译安装使用的时候通过-DNNG_ENABLE_TLS=ON选项打开。",[12,97,98],{},"之后可以通过命令行\u002F配置文件\u002F容器环境变量方式配置：",[100,101,102,117,128],"ul",{},[103,104,105,106,110,111],"li",{},"Running broker with ",[107,108,109],"em",{},"TLS"," via command line:",[38,112,115],{"className":113,"code":114,"language":43},[41],"nanomq broker start --url \"tls+nmq-tcp:\u002F\u002F0.0.0.0:8883\" [--cacert \u003Cpath>] [-E, --cert \u003Cpath>] [--key \u003Cpath>] [--keypass \u003Cpassword>] [--verify] [--fail]\n",[45,116,114],{"__ignoreMap":47},[103,118,105,119,121,122],{},[107,120,109],{}," via configuration file:",[38,123,126],{"className":124,"code":125,"language":43},[41],"## tls config ##\n\n## enable tls\n##\n## Value: true | false\ntls.enable=false\n\n## tls url\n##\n## Value: \"nmq-tls:\u002F\u002Fhost:port\"\ntls.url=nmq-tls:\u002F\u002F0.0.0.0:8883\n\n## tls key password\n## String containing the user's password. Only used if the private keyfile\n## is password-protected.\n##\n## Value: String\n## tls.key_password=yourpass\n\n## tls keyfile\n## Path to the file containing the user's private PEM-encoded key.\n##\n## Value: File\ntls.keyfile=\u002Fetc\u002Fcerts\u002Fkey.pem\n\n## tls cert file\n## Path to a file containing the user certificate.\n##\n## Value: File\ntls.certfile=\u002Fetc\u002Fcerts\u002Fcert.pem\n\n## tls ca cert file\n## Path to the file containing PEM-encoded CA certificates. The CA certificates\n## are used during server authentication and when building the client certificate chain.\n##\n## Value: File\ntls.cacertfile=\u002Fetc\u002Fcerts\u002Fcacert.pem\n\n## A server only does x509-path validation in mode verify_peer,\n## as it then sends a certificate request to the client (this\n## message is not sent if the verify option is verify_none).\n## You can then also want to specify option fail_if_no_peer_cert.\n##\n## Value: true: verify_peer | false: verify_none\ntls.verify_peer=false\n\n## Used together with {verify, verify_peer} by an SSL server. If set to true,\n## the server fails if the client does not have a certificate to send, that is,\n## sends an empty certificate.\n##\n## Value: true | false\ntls.fail_if_no_peer_cert=false\n\n## websocket tls url\n##\n## Value: \"nmq-wss:\u002F\u002Fhost:port\u002Fpath\"\nwebsocket.tls_url=nmq-wss:\u002F\u002F0.0.0.0:8084\u002Fmqtt\n",[45,127,125],{"__ignoreMap":47},[103,129,130,131,133],{},"Running Docker with ",[107,132,109],{}," and configuring via ENV：",[135,136,137,153],"table",{},[138,139,140],"thead",{},[141,142,143,147,150],"tr",{},[144,145,146],"th",{},"Variable",[144,148,149],{},"Type",[144,151,152],{},"Value",[154,155,156,168,179,189,199,209,219,229],"tbody",{},[141,157,158,162,165],{},[159,160,161],"td",{},"NANOMQ_TLS_ENABLE",[159,163,164],{},"Boolean",[159,166,167],{},"是否开启 TLS",[141,169,170,173,176],{},[159,171,172],{},"NANOMQ_TLS_URL",[159,174,175],{},"String",[159,177,178],{},"TLS 的监听 URL：'nmq-tls:\u002F\u002Fhost:port'.",[141,180,181,184,186],{},[159,182,183],{},"NANOMQ_TLS_CA_CERT_PATH",[159,185,175],{},[159,187,188],{},"TLS 的服务端证书路径（PEM-encoded CA certificates）",[141,190,191,194,196],{},[159,192,193],{},"NANOMQ_TLS_CERT_PATH",[159,195,175],{},[159,197,198],{},"TLS 的用户证书路径",[141,200,201,204,206],{},[159,202,203],{},"NANOMQ_TLS_KEY_PATH",[159,205,175],{},[159,207,208],{},"私有秘钥文件路径",[141,210,211,214,216],{},[159,212,213],{},"NANOMQ_TLS_KEY_PASSWORD",[159,215,175],{},[159,217,218],{},"用户指定的私有秘钥密码（如果指定使用）",[141,220,221,224,226],{},[159,222,223],{},"NANOMQ_TLS_VERIFY_PEER",[159,225,164],{},[159,227,228],{},"是否校验对端身份（双向认证）",[141,230,231,234,236],{},[159,232,233],{},"NANOMQ_TLS_FAIL_IF_NO_PEER_CERT",[159,235,164],{},[159,237,238],{},"当对端未携带证书进行连接时，MQTT 服务是否失败（双向认证）",[12,240,241],{},"使用 TLS 需要自行生成证书（Certificate Authority，CA）的认证和密钥，可以用 OpenSSL 工具生成 CA 证书，也可以使用 NanoMQ 自带的证书文件 (项目根目录\u002Fetc\u002Fcerts)。",[12,243,244,245,249],{},"在此我们就不再介绍 TLS 背景知识和用法教程。如需更多相关知识，请参阅博客文章：",[16,246,247],{"href":247,"rel":248},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fblog\u002Femqx-server-ssl-tls-secure-connection-configuration-guide",[65]," 。",[22,251,252],{"id":252},"共享订阅",[12,254,255,256,261,262,267,268,272,273,278],{},"共享订阅是 ",[16,257,260],{"href":258,"rel":259},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fblog\u002Fintroduction-to-mqtt-5",[65],"MQTT 5.0"," 协议引入的新特性，但 ",[16,263,266],{"href":264,"rel":265},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fproducts\u002Femqx",[65],"EMQX"," 在 ",[16,269,78],{"href":270,"rel":271},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fmqtt-guide",[65]," 3.1.1 中也已经实现。这相当于是订阅端的",[16,274,277],{"href":275,"rel":276},"https:\u002F\u002Fwww.emqx.com\u002Fzh\u002Fblog\u002Fmqtt-broker-clustering-part-2-sticky-session-load-balancing",[65],"负载均衡","功能，主要目的是解决当消费能力不足时直接增加订阅节点，从而导致产生大量重复消息的问题。NanoMQ 也在 MQTT 3.1.1 中支持了共享订阅，但目前只支持 Round-robin 和 Random 的分发均衡方式。",[22,280,282],{"id":281},"移除-c-模块","移除 C++ 模块",[12,284,285],{},"之前 NanoMQ 是 C\u002FC++混合项目。但为了达到边缘端的极致轻量级，在 0.6.0 版本我们移除了原先的 Nanolib 中的 C++ 模块，这能够大幅减少 NanoMQ 的安装包大小。",[22,287,289],{"id":288},"bug-修复","Bug 修复",[12,291,292],{},"本月我们修复了以下 3 个重要 Bug：",[294,295,296,299,302],"ol",{},[103,297,298],{},"修复了当客户端使用会话保持功能时，session present field 没有正确设置的问题。",[103,300,301],{},"修复了当客户端因为超时断开不会触发之前设置的遗愿消息（will msg）发布的问题。",[103,303,304],{},"修复了 MQTT v5 和 MQTT v3.1&v3.1.1 客户端之间消息互通兼容的问题。",[33,306,308],{"id":307},"url-配置修改","URL 配置修改",[12,310,311],{},"另外，需要社区各位用户注意的是，相较于之前的版本还有一个对于 NanoMQ 使用习惯的改变。为了未来多协议转换的准备，从 0.6.3 版本开始，我们将原来的 MQTT Broker 默认 URL 格式从“broker+tcp:\\ip:port” 修改为 “nmq-tcp:\\ip:port”，原来的 URL 将留作他用。",[22,313,315],{"id":314},"nanosdk-重构","NanoSDK 重构",[12,317,318],{},"本月 NanoSDK 迎来了新的 0.3 版本。在这一版本中，我们根据 NNG 项目维护者 Garrett 的意见和性能测试数据重构了协议层，减少内存消耗并维持 QoS 消息的高吞吐高性能，同时修复了一些 Bug。目前我们正在将 NanoSDK 的更新合并到下一版本 NanoMQ 中。",[12,320,321,322,249],{},"另外，为了广大用户能够更便捷地找到 NanoSDK，我们已将仓库地址从原先的 NNG fork 转为一个独立仓库：",[16,323,324],{"href":324,"rel":325},"https:\u002F\u002Fgithub.com\u002Fnanomq\u002FNanoSDK",[65],{"title":47,"searchDepth":327,"depth":327,"links":328},2,[329,334,335,336,337,340],{"id":24,"depth":327,"text":24,"children":330},[331,333],{"id":35,"depth":332,"text":36},3,{"id":50,"depth":332,"text":51},{"id":88,"depth":327,"text":89},{"id":252,"depth":327,"text":252},{"id":281,"depth":327,"text":282},{"id":288,"depth":327,"text":289,"children":338},[339],{"id":307,"depth":332,"text":308},{"id":314,"depth":327,"text":315},"\u002Fimages\u002Fblog\u002Fzh\u002Fnanomq-newsletter-202202\u002Fcover.webp",684,1520,"2022-02-26","本月，新发布的0.6.2版本中，我们进一步完善了 NanoMQ 的命令行工具，为其增加了 TLS 端口支持，同时进一步优化重构了 NanoSDK。",false,"md",{},true,"\u002Fzh\u002Fblog\u002Fnanomq-newsletter-202202",{"title":6,"description":345},{"loc":350,"lastmod":344},"zh\u002Fblog\u002Fnanomq-newsletter-202202",[355],"NanoMQ Newsletter","hKe1ubMzwopFByjPCDzRQlY8tBQ75XJNB8Q_nElxrZo",1794542897737]