{"id":94426,"date":"2024-06-25T11:19:52","date_gmt":"2024-06-25T03:19:52","guid":{"rendered":"https:\/\/www.techphant.cn\/?p=94426"},"modified":"2024-06-25T11:20:00","modified_gmt":"2024-06-25T03:20:00","slug":"mxyyxznyc-2","status":"publish","type":"post","link":"https:\/\/www.techphant.cn\/blog\/94426.html","title":{"rendered":"MQTT\u534f\u8bae\u8fd0\u884c\u5728\u7f51\u7edc\u534f\u8bae\u6808\u54ea\u4e00\u5c42"},"content":{"rendered":"\n
\u3000\u3000MQTT\u534f\u8bae<\/strong>\u8fd0\u884c\u5728\u7f51\u7edc\u534f\u8bae\u6808\u7684\u5e94\u7528\u5c42\u3002\u5b83\u4f7f\u7528TCP\u4f5c\u4e3a\u5e95\u5c42\u4f20\u8f93\u534f\u8bae\uff0c\u901a\u8fc7\u53d1\u5e03-\u8ba2\u9605\u6a21\u5f0f\u5b9e\u73b0\u53ef\u9760\u7684\u6d88\u606f\u4f20\u8f93\u3002MQTT\u534f\u8bae\u4e0eHTTP\u534f\u8bae\u4e00\u6837\uff0c\u5de5\u4f5c\u5728TCP\/IP\u56db\u5c42\u6a21\u578b\u4e2d\u7684\u6700\u4e0a\u5c42(\u5e94\u7528\u5c42)\u3002\u6b64\u5916\uff0cMQTT\u534f\u8bae\u4e0d\u4f9d\u8d56\u4e8e\u4f20\u8f93\u5c42\u534f\u8bae\uff0c\u53ef\u4ee5\u4f7f\u7528TCP\/IP\u3001WebSocket\u7b49\u4f20\u8f93\u534f\u8bae\u3002\u56e0\u6b64\uff0cMQTT\u534f\u8bae\u8fd0\u884c\u5728\u7f51\u7edc\u534f\u8bae\u6808\u7684\u5e94\u7528\u5c42\u3002<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u5728TCP\/IP\u56db\u5c42\u6a21\u578b\u4e2d\u4e3b\u8981\u4f5c\u7528\u662f\u4f5c\u4e3a\u4f20\u8f93\u5c42\u534f\u8bae\uff0c\u4f9d\u8d56\u4e8eTCP\u534f\u8bae\u8fdb\u884c\u53ef\u9760\u7684\u6570\u636e\u4f20\u8f93\u3002\u5177\u4f53\u6765\u8bf4\uff0cMQTT\u534f\u8bae\u901a\u8fc7\u5efa\u7acb\u5230Broker\u7684TCP\u8fde\u63a5\u6765\u5b9e\u73b0\u6d88\u606f\u7684\u53d1\u5e03\u548c\u8ba2\u9605\uff0c\u786e\u4fdd\u4e86\u6d88\u606f\u7684\u53ef\u9760\u4f20\u8f93\u548c\u6709\u5e8f\u63a5\u6536\u3002\u867d\u7136MQTT\u534f\u8bae\u672c\u8eab\u5e76\u4e0d\u5f3a\u5236\u6307\u5b9a\u4f7f\u7528\u67d0\u79cd\u4f20\u8f93\u534f\u8bae\uff0c\u4f46\u5b83\u901a\u5e38\u4e0eTCP\u534f\u8bae\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u63d0\u4f9b\u57fa\u7840\u7684\u901a\u4fe1\u652f\u6301\u3002<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u4e0eHTTP\u534f\u8bae\u5728\u7f51\u7edc\u901a\u4fe1\u4e2d\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u65b9\u5f0f\u5b9e\u73b0\u4e92\u64cd\u4f5c\uff0c\u5c3d\u7ba1\u5b83\u4eec\u5728\u8bbe\u8ba1\u548c\u5e94\u7528\u573a\u666f\u4e0a\u6709\u6240\u4e0d\u540c\u3002<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u53d1\u5e03-\u8ba2\u9605\u534f\u8bae\uff0c\u7279\u522b\u9002\u7528\u4e8e\u7269\u8054\u7f51\u8bbe\u5907\u95f4\u7684\u901a\u4fe1\u3002\u5b83\u652f\u6301\u957f\u8fde\u63a5\uff0c\u9002\u5408\u4f4e\u5e26\u5bbd\u548c\u4e0d\u7a33\u5b9a\u7f51\u7edc\u73af\u5883\u3002\u800cHTTP\u534f\u8bae\u5219\u662f\u4e00\u4e2a\u8bf7\u6c42-\u54cd\u5e94\u534f\u8bae\uff0c\u4e3b\u8981\u7528\u4e8eWeb\u670d\u52a1\u548c\u6d4f\u89c8\u5668\u95f4\u7684\u4ea4\u4e92\uff0c\u901a\u5e38\u662f\u77ed\u8fde\u63a5\u3002<\/p>\n\n\n\n \u3000\u3000\u4e3a\u4e86\u5b9e\u73b0MQTT\u4e0eHTTP\u7684\u4e92\u64cd\u4f5c\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n\n\n\n \u3000\u3000\u867d\u7136MQTT\u548cHTTP\u5728\u8bbe\u8ba1\u548c\u5e94\u7528\u573a\u666f\u4e0a\u6709\u5f88\u5927\u7684\u533a\u522b\uff0c\u4f46\u901a\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\u3001SDK\u96c6\u6210\u3001\u4e2d\u95f4\u4ef6\u548cAPI\u7f51\u5173\u7b49\u6280\u672f\u624b\u6bb5\uff0c\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e24\u79cd\u534f\u8bae\u5728\u7f51\u7edc\u901a\u4fe1\u4e2d\u7684\u4e92\u64cd\u4f5c\u3002<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u4f7f\u7528TCP\/IP\u548cWebSocket\u7b49\u4f20\u8f93\u534f\u8bae\u5177\u6709\u4ee5\u4e0b\u4f18\u52bf\u548c\u9650\u5236\uff1a<\/p>\n\n\n\n \u3000\u3000\u8981\u914d\u7f6e\u548c\u4f18\u5316MQTT\u670d\u52a1\u5668\u4ee5\u63d0\u9ad8\u6d88\u606f\u4f20\u9012\u7684\u53ef\u9760\u6027\u548c\u6027\u80fd\uff0c\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n\n\n\n \u3000\u3000\u4f7f\u7528\u9ad8\u6027\u80fd\u6846\u67b6<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u4f7f\u7528Netty\u6846\u67b6\u6784\u5efaMQTT\u670d\u52a1\u5668\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5176\u6027\u80fd\u3002Netty\u662f\u4e00\u4e2a\u9ad8\u6027\u80fd\u3001\u5f02\u6b65\u4e8b\u4ef6\u9a71\u52a8\u7684\u7f51\u7edc\u5e94\u7528\u6846\u67b6\uff0c\u9002\u7528\u4e8e\u5f00\u53d1\u9ad8\u5e76\u53d1\u3001\u4f4e\u5ef6\u8fdf\u7684\u7f51\u7edc\u901a\u4fe1\u5e94\u7528\u3002<\/p>\n\n\n\n \u3000\u3000\u52a8\u6001\u8d1f\u8f7d\u5747\u8861<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u901a\u8fc7\u52a8\u6001\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff0c\u53ef\u4ee5\u5bf9\u6d88\u606f\u961f\u5217\u3001CPU\u5229\u7528\u7387\u548c\u5185\u5b58\u5229\u7528\u7387\u8fdb\u884c\u5206\u6790\uff0c\u5e76\u901a\u8fc7\u6743\u503c\u4fee\u6539\u51fd\u6570\u4f18\u5316\u66f4\u65b0\uff0c\u4ece\u800c\u5b9e\u73b0\u7528\u6237\u8bf7\u6c42\u7684\u5747\u8861\u5206\u914d\u3002<\/p>\n\n\n\n \u3000\u3000\u6d88\u606f\u786e\u8ba4\u548c\u91cd\u4f20\u673a\u5236<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u652f\u6301\u6d88\u606f\u7684\u786e\u8ba4\u548c\u91cd\u4f20\u673a\u5236\uff0c\u4fdd\u6301\u4f1a\u8bdd\u548c\u6301\u4e45\u8ba2\u9605\uff0c\u4ee5\u53ca\u81ea\u52a8\u91cd\u8fde\uff0c\u4ee5\u786e\u4fdd\u6d88\u606f\u7684\u5b8c\u6574\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n\n\n\n \u3000\u3000\u7f13\u5b58\u5ba2\u6237\u7aef\u4fe1\u606f<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u5c06MQTT\u5ba2\u6237\u7aef\u4fe1\u606f\u7f13\u5b58\u5230Redis\u7b49\u7f13\u5b58\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u51cf\u8f7bMQTT\u670d\u52a1\u5668\u7684\u8d1f\u62c5\uff0c\u63d0\u9ad8\u5904\u7406\u5927\u91cf\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u80fd\u529b\u3002<\/p>\n\n\n\n \u3000\u3000\u6027\u80fd\u8c03\u4f18<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u5bf9MQTT\u670d\u52a1\u5668\u8fdb\u884c\u6027\u80fd\u6d4b\u8bd5\u548c\u8c03\u4f18\u64cd\u4f5c\uff0c\u4f8b\u5982\u5728\u5355\u670d\u52a1\u5668\u4e0a\u652f\u6301100\u4e07\u8fde\u63a5\u548c30\u4e07\u6d88\u606f\u541e\u5410\u91cf\u7684\u6d4b\u8bd5\uff0c\u53ef\u4ee5\u5e2e\u52a9\u53d1\u73b0\u5e76\u89e3\u51b3\u6027\u80fd\u74f6\u9888\u3002<\/p>\n\n\n\n \u3000\u3000\u5408\u7406\u914d\u7f6e\u670d\u52a1\u5668\u8d44\u6e90<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u786e\u4fdd\u670d\u52a1\u5668\u6709\u8db3\u591f\u7684CPU\u548c\u5185\u5b58\u8d44\u6e90\u6765\u652f\u6301\u9ad8\u5e76\u53d1\u8fde\u63a5\u548c\u6d88\u606f\u5904\u7406\u9700\u6c42\u3002\u4f8b\u5982\uff0c\u4f7f\u752816\u683832GB\u7684\u670d\u52a1\u5668\u53ef\u4ee5\u652f\u6301100\u4e07\u8fde\u63a5\u548c30\u4e07\u6d88\u606f\u541e\u5410\u91cf\u3002<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u5728\u4e0d\u540c\u5e94\u7528\u573a\u666f\u4e0b\u7684\u6700\u4f73\u5b9e\u8df5\u6848\u4f8b\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a<\/p>\n\n\n\n \u3000\u3000MQTT\u5e7f\u6cdb\u5e94\u7528\u4e8e\u7269\u8054\u7f51\u8bbe\u5907\u4e4b\u95f4\u7684\u901a\u4fe1\uff0c\u4f8b\u5982\u667a\u80fd\u5bb6\u5c45\u3001\u667a\u80fd\u57ce\u5e02\u548c\u5de5\u4e1a\u81ea\u52a8\u5316\u7b49\u9886\u57df\u3002\u901a\u8fc7MQTT\u534f\u8bae\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u5404\u79cd\u8bbe\u5907\u7684\u8fdc\u7a0b\u63a7\u5236\u548c\u5b9e\u65f6\u76d1\u63a7\u3002<\/p>\n\n\n\n \u3000\u3000\u5728\u4f20\u611f\u5668\u6570\u636e\u4f20\u8f93\u65b9\u9762\uff0cMQTT\u80fd\u591f\u9ad8\u6548\u5730\u5c06\u4f20\u611f\u5668\u6536\u96c6\u5230\u7684\u6570\u636e\u4f20\u8f93\u5230\u4e2d\u5fc3\u670d\u52a1\u5668\u6216\u5904\u7406\u8282\u70b9\uff0c\u9002\u7528\u4e8e\u9700\u8981\u5b9e\u65f6\u6570\u636e\u53cd\u9988\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n\n\n\n \u3000\u3000\u5728\u8f66\u8054\u7f51\u573a\u666f\u4e2d\uff0cMQTT\u534f\u8bae\u80fd\u591f\u652f\u6301\u6d77\u91cf\u8f66\u673a\u7cfb\u7edf\u7684\u7075\u6d3b\u3001\u5feb\u901f\u63a5\u5165\uff0c\u5e76\u4fdd\u8bc1\u590d\u6742\u7f51\u7edc\u73af\u5883\u4e0b\u7684\u6d88\u606f\u5b9e\u65f6\u6027\u548c\u53ef\u9760\u6027\u3002\u4f8b\u5982\uff0c\u5c0f\u7c73\u5728\u5176IoT\u751f\u6001\u4e2d\u4f7f\u7528\u4e86RocketMQ-MQTT\u67b6\u6784\uff0c\u4ee5\u63d0\u9ad8\u541e\u5410\u6027\u80fd\u3001\u5b9e\u65f6\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n\n\n\n \u3000\u3000\u5728\u5171\u4eab\u5145\u7535\u5b9d\u4e1a\u52a1\u573a\u666f\u4e2d\uff0cMQTT\u534f\u8bae\u88ab\u7528\u4e8e\u8bbe\u8ba1Topic\u548cPayload\uff0c\u4ee5\u5b9e\u73b0C\u7aef\u7528\u6237\u7684\u64cd\u4f5c(\u5982\u626b\u7801\u4e0b\u5355\u3001\u501f\u51fa\u5145\u7535\u5b9d)\u4e0e\u540e\u53f0\u6307\u4ee4\u7684\u540c\u6b65\u4f20\u8f93\u3002\u8fd9\u79cd\u8bbe\u8ba1\u786e\u4fdd\u4e86\u4e1a\u52a1\u6d41\u7a0b\u7684\u987a\u7545\u548c\u6570\u636e\u4f20\u8f93\u7684\u51c6\u786e\u6027\u3002<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u5728\u667a\u80fd\u5236\u9020\u548c\u80fd\u6e90\u7ba1\u7406\u9886\u57df\u4e5f\u6709\u5e7f\u6cdb\u5e94\u7528\u3002\u5b83\u80fd\u591f\u5e2e\u52a9\u4f01\u4e1a\u5728\u6709\u9650\u7684\u5e26\u5bbd\u4e0b\uff0c\u9ad8\u6548\u5730\u8fdb\u884c\u8bbe\u5907\u6570\u636e\u901a\u4fe1\uff0c\u4ece\u800c\u4f18\u5316\u751f\u4ea7\u6d41\u7a0b\u548c\u80fd\u6e90\u4f7f\u7528\u6548\u7387\u3002<\/p>\n\n\n\n \u3000\u3000\u5728\u91d1\u878d\u652f\u4ed8\u9886\u57df\uff0cMQTT\u534f\u8bae\u56e0\u5176\u4f4e\u5ef6\u8fdf\u548c\u9ad8\u53ef\u9760\u6027\u7279\u70b9\uff0c\u88ab\u7528\u4e8e\u5b9e\u73b0\u652f\u4ed8\u7cfb\u7edf\u7684\u5b9e\u65f6\u6570\u636e\u4f20\u8f93\u548c\u5904\u7406\uff0c\u786e\u4fdd\u4ea4\u6613\u7684\u5b89\u5168\u6027\u548c\u53ca\u65f6\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" MQTT\u534f\u8bae\u8fd0\u884c\u5728\u7f51\u7edc\u534f\u8bae\u6808\u7684\u5e94\u7528\u5c42\u3002\u5b83\u4f7f\u7528TCP\u4f5c\u4e3a\u5e95\u5c42\u4f20\u8f93\u534f\u8bae\uff0c\u901a\u8fc7\u53d1\u5e03-\u8ba2\u9605\u6a21\u5f0f\u5b9e\u73b0\u53ef\u9760\u7684\u6d88\u606f\u4f20\u8f93\u3002MQTT\u534f\u8bae\u4e0eHTTP\u534f\u8bae\u4e00\u6837\uff0c\u5de5\u4f5c\u5728TCP\/IP\u56db\u5c42\u6a21\u578b\u4e2d\u7684\u6700\u4e0a\u5c42(\u5e94\u7528\u5c42)\u3002<\/p>\n","protected":false},"author":1,"featured_media":90925,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[36],"tags":[46],"class_list":["post-94426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-m"],"_links":{"self":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/94426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/comments?post=94426"}],"version-history":[{"count":0,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/94426\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media\/90925"}],"wp:attachment":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media?parent=94426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/categories?post=94426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/tags?post=94426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u3000\u3000\u4e00\u3001 MQTT\u534f\u8bae\u5728TCP\/IP\u56db\u5c42\u6a21\u578b\u4e2d\u7684\u5177\u4f53\u4f5c\u7528\u662f\u4ec0\u4e48?<\/h2>\n\n\n\n
\u3000\u3000\u4e8c\u3001 MQTT\u534f\u8bae\u4e0eHTTP\u534f\u8bae\u5728\u7f51\u7edc\u901a\u4fe1\u4e2d\u5982\u4f55\u4e92\u64cd\u4f5c?<\/h2>\n\n\n\n
\n
\u3000\u3000\u4e09\u3001 MQTT\u534f\u8bae\u4f7f\u7528TCP\/IP\u3001WebSocket\u7b49\u4f20\u8f93\u534f\u8bae\u7684\u4f18\u52bf\u548c\u9650\u5236\u662f\u4ec0\u4e48?<\/h2>\n\n\n\n
\u3000\u30001. \u4f18\u52bf<\/h3>\n\n\n\n
\n
\u3000\u30002. \u9650\u5236<\/h3>\n\n\n\n
\n
\u3000\u3000\u56db\u3001 \u5982\u4f55\u914d\u7f6e\u548c\u4f18\u5316MQTT\u670d\u52a1\u5668\u4ee5\u63d0\u9ad8\u6d88\u606f\u4f20\u9012\u7684\u53ef\u9760\u6027\u548c\u6027\u80fd?<\/h2>\n\n\n\n
\u3000\u3000\u4e94\u3001 MQTT\u534f\u8bae\u5728\u4e0d\u540c\u5e94\u7528\u573a\u666f\u4e0b\u7684\u6700\u4f73\u5b9e\u8df5\u6848\u4f8b\u6709\u54ea\u4e9b?<\/h2>\n\n\n\n