{"id":94160,"date":"2024-06-18T15:38:34","date_gmt":"2024-06-18T07:38:34","guid":{"rendered":"https:\/\/www.techphant.cn\/?p=94160"},"modified":"2024-06-18T15:38:45","modified_gmt":"2024-06-18T07:38:45","slug":"mxxzldjjs","status":"publish","type":"post","link":"https:\/\/www.techphant.cn\/blog\/94160.html","title":{"rendered":"MQTT\u6d88\u606f\u8d28\u91cf\u7b49\u7ea7\u4ecb\u7ecd"},"content":{"rendered":"\n
\u3000\u3000MQTT\u534f\u8bae<\/strong>\u4e2d\u7684\u670d\u52a1\u8d28\u91cf(Quality of Service\uff0c\u7b80\u79f0QoS)<\/strong>\u7b49\u7ea7\u662f\u786e\u4fdd\u6d88\u606f\u5728\u4e0d\u540c\u7f51\u7edc\u73af\u5883\u4e0b\u53ef\u9760\u4f20\u9012\u7684\u91cd\u8981\u673a\u5236\u3002MQTT\u5b9a\u4e49\u4e86\u4e09\u4e2a\u4e0d\u540c\u7684QoS\u7b49\u7ea7\uff0c\u5206\u522b\u662fQoS 0\u3001QoS 1\u548cQoS 2.\u6bcf\u4e2a\u7b49\u7ea7\u63d0\u4f9b\u4e86\u4e0d\u540c\u7a0b\u5ea6\u7684\u6d88\u606f\u4f20\u9012\u4fdd\u8bc1\u3002<\/p>\n\n\n\n \u3000\u3000QoS 0(\u6700\u591a\u4e00\u6b21)<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u8fd9\u662f\u6700\u57fa\u672c\u7684QoS\u7ea7\u522b\uff0c\u4fdd\u8bc1\u6d88\u606f\u6700\u591a\u88ab\u53d1\u9001\u4e00\u6b21\u3002\u5982\u679c\u6d88\u606f\u6ca1\u6709\u6210\u529f\u9001\u8fbe\u63a5\u6536\u7aef\uff0c\u5219\u4e0d\u4f1a\u8fdb\u884c\u91cd\u8bd5\u3002<\/p>\n\n\n\n \u3000\u3000\u4f7f\u7528QoS 0\u65f6\uff0c\u6d88\u606f\u53ef\u80fd\u4f1a\u4e22\u5931\uff0c\u4f46\u4f20\u8f93\u901f\u5ea6\u6700\u5feb\u3002<\/p>\n\n\n\n \u3000\u3000QoS 1(\u81f3\u5c11\u4e00\u6b21)<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u8fd9\u4e2a\u7ea7\u522b\u7684QoS\u4fdd\u8bc1\u6d88\u606f\u81f3\u5c11\u88ab\u53d1\u9001\u4e00\u6b21\u5230\u63a5\u6536\u7aef\u3002\u5982\u679c\u6d88\u606f\u6ca1\u6709\u6210\u529f\u9001\u8fbe\uff0c\u53ef\u80fd\u4f1a\u91cd\u590d\u53d1\u9001\uff0c\u76f4\u5230\u8fbe\u5230\u6700\u5927\u91cd\u8bd5\u6b21\u6570\u3002<\/p>\n\n\n\n \u3000\u3000QoS 1\u53ef\u4ee5\u786e\u4fdd\u6d88\u606f\u6700\u7ec8\u5230\u8fbe\u63a5\u6536\u7aef\uff0c\u4f46\u53ef\u80fd\u4f1a\u6709\u91cd\u590d\u7684\u60c5\u51b5\u53d1\u751f\u3002<\/p>\n\n\n\n \u3000\u3000QoS 2(\u6070\u597d\u4e00\u6b21)<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u8fd9\u662f\u6700\u9ad8\u7684QoS\u7ea7\u522b\uff0c\u4fdd\u8bc1\u6d88\u606f\u6070\u597d\u88ab\u53d1\u9001\u4e00\u6b21\u5230\u63a5\u6536\u7aef\uff0c\u5e76\u4e14\u4e0d\u4f1a\u91cd\u590d\u3002<\/p>\n\n\n\n \u3000\u3000\u5728QoS 2\u6a21\u5f0f\u4e0b\uff0c\u53d1\u9001\u7aef\u9700\u8981\u63a5\u6536\u7aef\u786e\u8ba4\u6d88\u606f\u5df2\u6210\u529f\u63a5\u6536\uff0c\u53ea\u6709\u5728\u63a5\u6536\u5230\u786e\u8ba4\u540e\u624d\u4f1a\u53d1\u9001\u4e0b\u4e00\u4e2a\u6d88\u606f\u3002<\/p>\n\n\n\n \u3000\u3000QoS 2\u63d0\u4f9b\u4e86\u6700\u9ad8\u7684\u6d88\u606f\u4f20\u9012\u53ef\u9760\u6027\uff0c\u4f46\u4e5f\u9700\u8981\u66f4\u591a\u7684\u7f51\u7edc\u8d44\u6e90\u548c\u590d\u6742\u7684\u5904\u7406\u673a\u5236\u3002<\/p>\n\n\n\n \u3000\u3000\u901a\u8fc7\u9009\u62e9\u5408\u9002\u7684QoS\u7b49\u7ea7\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u5e94\u7528\u573a\u666f\u7684\u9700\u6c42\u6765\u5e73\u8861\u6d88\u606f\u7684\u53ef\u9760\u6027\u548c\u4f20\u8f93\u6548\u7387\u3002<\/p>\n\n\n\n \u3000\u3000\u5728MQTT\u534f\u8bae\u4e2d\uff0cQoS(Quality of Service)\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u670d\u52a1\u8d28\u91cf\u7b49\u7ea7\uff1aQoS 0\u3001QoS 1\u548cQoS 2.\u6bcf\u79cdQoS\u7b49\u7ea7\u7684\u5177\u4f53\u5b9e\u73b0\u673a\u5236\u5982\u4e0b\uff1a<\/p>\n\n\n\n \u3000\u3000QoS 0(\u6700\u591a\u4e00\u6b21\u9001\u8fbe)<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u53d1\u9001\u7aef\u53d1\u9001\u6d88\u606f\u540e\u5c31\u4e0d\u7ba1\u4e86\uff0c\u6700\u591a\u53ea\u4fdd\u8bc1\u6d88\u606f\u88ab\u4f20\u9012\u4e00\u6b21\u3002<\/p>\n\n\n\n \u3000\u3000\u8fd9\u79cd\u6a21\u5f0f\u4e0b\uff0c\u53d1\u9001\u7aef\u4e0d\u4f1a\u7b49\u5f85\u4efb\u4f55\u786e\u8ba4\uff0c\u6d88\u606f\u4e00\u65e6\u53d1\u9001\u51fa\u53bb\u5c31\u201cfire and forget\u201d\u3002<\/p>\n\n\n\n \u3000\u3000QoS 1(\u81f3\u5c11\u4e00\u6b21\u9001\u8fbe)<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000\u53d1\u9001\u7aef\u53d1\u9001\u6d88\u606f\u540e\u9700\u8981\u7b49\u5f85\u63a5\u6536\u8005\u7684ACK(Acknowledgement)\u786e\u8ba4\u3002<\/p>\n\n\n\n \u3000\u3000\u5982\u679c\u6ca1\u6709\u6536\u5230ACK\uff0c\u53d1\u9001\u7aef\u4f1a\u91cd\u65b0\u53d1\u9001\u6d88\u606f\uff0c\u76f4\u5230\u6536\u5230\u4e3a\u6b62\u3002<\/p>\n\n\n\n \u3000\u3000\u8fd9\u79cd\u6a21\u5f0f\u80fd\u4fdd\u8bc1\u6d88\u606f\u81f3\u5c11\u80fd\u5230\u8fbe\u4e00\u6b21\uff0c\u4f46\u65e0\u6cd5\u4fdd\u8bc1\u6d88\u606f\u7684\u987a\u5e8f\u6216\u907f\u514d\u91cd\u590d\u3002<\/p>\n\n\n\n \u3000\u3000QoS 2(\u51c6\u786e\u4e00\u6b21\u9001\u8fbe)<\/strong>\uff1a<\/p>\n\n\n\n \u3000\u3000QoS 2\u662f\u6700\u9ad8\u7684\u670d\u52a1\u8d28\u91cf\u7b49\u7ea7\uff0c\u5b83\u4f7f\u7528PUBLISH\u548cPUBREC\u62a5\u6587\u6765\u4fdd\u8bc1\u6d88\u606f\u7684\u5230\u8fbe\u3002<\/p>\n\n\n\n \u3000\u3000\u53d1\u9001\u7aef\u53d1\u9001\u6d88\u606f\u540e\uff0c\u63a5\u6536\u7aef\u4f1a\u56de\u590dPUBREC\u62a5\u6587\uff0c\u53d1\u9001\u7aef\u6536\u5230\u540e\u7ee7\u7eed\u53d1\u9001PUBREL\u62a5\u6587\u3002<\/p>\n\n\n\n \u3000\u3000\u63a5\u6536\u7aef\u6536\u5230PUBREL\u62a5\u6587\u540e\u4f1a\u56de\u590dPUBCOMP\u62a5\u6587\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u6d88\u606f\u4e0d\u4f1a\u91cd\u590d\u3002<\/p>\n\n\n\n \u3000\u3000QoS 2\u901a\u8fc7\u56db\u6b21\u4ea4\u4e92\u6765\u786e\u4fdd\u6d88\u606f\u7684\u51c6\u786e\u9001\u8fbe\uff0c\u5305\u62ecPUBLISH\u3001PUBREC\u3001PUBREL\u548cPUBCOMP\u56db\u4e2a\u6b65\u9aa4\u3002<\/p>\n\n\n\n \u3000\u3000QoS 0\u662f\u6700\u7b80\u5355\u4e14\u8d44\u6e90\u6d88\u8017\u6700\u5c11\u7684\u6a21\u5f0f\uff0c\u9002\u7528\u4e8e\u5bf9\u6d88\u606f\u53ef\u9760\u6027\u8981\u6c42\u4e0d\u9ad8\u7684\u573a\u666f;QoS 1\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u6d88\u606f\u53ef\u9760\u6027\u4fdd\u969c\uff0c\u9002\u7528\u4e8e\u9700\u8981\u786e\u8ba4\u6d88\u606f\u5230\u8fbe\u4f46\u4e0d\u9700\u8981\u4e25\u683c\u987a\u5e8f\u7684\u573a\u666f;<\/p>\n\n\n\n \u3000\u3000\u6839\u636e\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\u9009\u62e9MQTT\u6d88\u606f\u7684QoS\u7b49\u7ea7\uff0c\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u5efa\u8bae\uff1a<\/p>\n\n\n\n \u3000\u3000\u9009\u62e9\u5408\u9002\u7684QoS\u7ea7\u522b\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u8fdb\u884c\u5224\u65ad\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u4e0d\u90a3\u4e48\u91cd\u8981\u7684\u6d88\u606f\uff0c\u53ef\u4ee5\u9009\u62e9QoS 0\u7ea7\u522b\u4ee5\u51cf\u5c11\u7f51\u7edc\u5f00\u9500;<\/p>\n\n\n\n \u3000\u3000\u5728QoS 2\u6a21\u5f0f\u4e0b\uff0c\u5904\u7406\u63a5\u6536\u7aef\u786e\u8ba4\u4ee5\u786e\u4fdd\u6d88\u606f\u7684\u552f\u4e00\u6027\u4e3b\u8981\u4f9d\u8d56\u4e8e\u6d88\u606fID\u7684\u673a\u5236\u3002QoS 2\u6a21\u5f0f\u4fdd\u8bc1\u6d88\u606f\u4ec5\u4f20\u9001\u5230\u76ee\u7684\u5730\u4e00\u6b21\uff0c\u5e76\u4e14\u5e26\u6709\u552f\u4e00\u6d88\u606fID\u7684\u6d88\u606f\u4f1a\u5b58\u50a8\u4e24\u6b21\uff0c\u4e00\u6b21\u6765\u81ea\u53d1\u9001\u8005\uff0c\u4e00\u6b21\u6765\u81ea\u63a5\u6536\u8005\u3002\u8fd9\u79cd\u673a\u5236\u786e\u4fdd\u4e86\u6d88\u606f\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u4e0d\u4f1a\u91cd\u590d\u6216\u4e22\u5931\u3002<\/p>\n\n\n\n \u3000\u3000\u5177\u4f53\u6765\u8bf4\uff0cRabbitMQ\u63d0\u4f9b\u4e86\u591a\u79cd\u6d88\u606f\u786e\u8ba4\u673a\u5236\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002\u4f8b\u5982\uff0c\u6d88\u8d39\u8005\u53ef\u4ee5\u5728\u8ba2\u9605\u961f\u5217\u65f6\u6307\u5b9aautoAck\u53c2\u6570\uff0c\u5f53autoAck\u4e3afalse\u65f6\uff0cRabbitMQ\u4f1a\u7b49\u5f85\u6d88\u8d39\u8005\u663e\u5f0f\u5730\u56de\u590d\u786e\u8ba4\u4fe1\u53f7\u540e\u624d\u4ece\u5185\u5b58(\u6216\u8005\u78c1\u76d8)\u4e2d\u5220\u9664\u6d88\u606f\u3002\u6b64\u5916\uff0cRabbitMQ\u8fd8\u652f\u6301Confirm\u6a21\u5f0f\uff0c\u901a\u8fc7confirmCallback\u65b9\u6cd5\u6765\u5904\u7406\u6d88\u606f\u786e\u8ba4\u3002\u5728Confirm\u6a21\u5f0f\u4e0b\uff0c\u751f\u4ea7\u8005\u5728\u53d1\u5e03\u6d88\u606f\u65f6\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2aCorrelationData\uff0c\u8fd9\u4e2a\u6570\u636e\u4f1a\u88ab\u4fdd\u5b58\u5230\u6d88\u606f\u5934\u4e2d\u3002\u5f53\u6d88\u606f\u6295\u9012\u5230Broker\u65f6\uff0c\u4f1a\u89e6\u53d1\u751f\u4ea7\u8005\u6307\u5b9a\u7684ConfirmCallback\uff0c\u8fd9\u4e2a\u503c\u4e5f\u4f1a\u88ab\u8fd4\u56de\uff0c\u4ee5\u8fdb\u884c\u5bf9\u7167\u5904\u7406\u3002<\/p>\n\n\n\n \u3000\u3000\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0cMQTT\u6d88\u606f\u4f20\u9012\u7684\u6700\u4f73\u5b9e\u8df5\u548c\u6848\u4f8b\u7814\u7a76\u6db5\u76d6\u4e86\u591a\u4e2a\u9886\u57df\u548c\u5177\u4f53\u7684\u5e94\u7528\u573a\u666f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5178\u578b\u7684\u5e94\u7528\u6848\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n\n\n\n \u3000\u3000MQTT\u534f\u8bae\u5b9a\u4e49\u4e86\u4e09\u79cd\u4e0d\u540c\u7684QoS\u7b49\u7ea7\uff0c\u6bcf\u79cd\u7b49\u7ea7\u90fd\u6709\u5176\u72ec\u7279\u7684\u884c\u4e3a\u548c\u9002\u7528\u573a\u666f\u3002\u8fd9\u4e9b\u7b49\u7ea7\u5206\u522b\u662f\uff1a<\/p>\n\n\n\n \u3000\u3000\u4f7f\u7528\u4e0d\u540c\u7684QoS\u7b49\u7ea7\u4f1a\u5bf9MQTT\u7f51\u7edc\u6027\u80fd\u4ea7\u751f\u663e\u8457\u5f71\u54cd\uff1a<\/p>\n\n\n\n \u3000\u3000\u6b64\u5916\uff0c\u9009\u62e9\u5408\u9002\u7684QoS\u7b49\u7ea7\u8fd8\u9700\u8981\u8003\u8651\u5176\u4ed6\u56e0\u7d20\uff0c\u5982\u786c\u4ef6\u8d44\u6e90\u3001\u64cd\u4f5c\u7cfb\u7edf\u53c2\u6570\u548c\u6d88\u606f\u5927\u5c0f\u7b49\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5fc5\u987b\u4ed4\u7ec6\u5e73\u8861QoS\u7b49\u7ea7\u4ee5\u8fbe\u5230\u6700\u4f73\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u4e4b\u95f4\u7684\u6298\u8877\u3002<\/p>\n\n\n\n \u3000\u3000\u603b\u4e4b\uff0cQoS\u7b49\u7ea7\u5bf9MQTT\u7f51\u7edc\u6027\u80fd\u7684\u5f71\u54cd\u4e3b\u8981\u4f53\u73b0\u5728\u5ef6\u8fdf\u3001\u7f51\u7edc\u8d1f\u8f7d\u548c\u6d88\u606f\u53ef\u9760\u6027\u4e4b\u95f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" MQTT\u534f\u8bae\u4e2d\u7684\u670d\u52a1\u8d28\u91cf(Quality of Service\uff0c\u7b80\u79f0QoS)\u7b49\u7ea7\u662f\u786e\u4fdd\u6d88\u606f\u5728\u4e0d\u540c\u7f51\u7edc\u73af\u5883\u4e0b\u53ef\u9760\u4f20\u9012\u7684\u91cd\u8981\u673a\u5236\u3002MQTT\u5b9a\u4e49\u4e86\u4e09\u4e2a\u4e0d\u540c\u7684QoS\u7b49\u7ea7<\/p>\n","protected":false},"author":1,"featured_media":90924,"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,169],"class_list":["post-94160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-m","tag-qos"],"_links":{"self":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/94160"}],"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=94160"}],"version-history":[{"count":0,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/94160\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media\/90924"}],"wp:attachment":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media?parent=94160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/categories?post=94160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/tags?post=94160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\u3000\u3000\u4e00\u3001 MQTT\u534f\u8bae\u4e2dQoS 0\u3001QoS 1\u548cQoS 2\u7684\u5177\u4f53\u5b9e\u73b0\u673a\u5236\u662f\u4ec0\u4e48?<\/h2>\n\n\n\n
\u3000\u3000\u4e8c\u3001 \u5982\u4f55\u6839\u636e\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\u9009\u62e9MQTT\u6d88\u606f\u7684QoS\u7b49\u7ea7?<\/h2>\n\n\n\n
\u3000\u30001. QoS 0(\u6700\u591a\u4e00\u6b21\u4f20\u8f93)<\/strong>\uff1a<\/h3>\n\n\n\n
\n
\u3000\u30002. QoS 1(\u81f3\u5c11\u4e00\u6b21\u4f20\u8f93)<\/strong>\uff1a<\/h3>\n\n\n\n
\n
\u3000\u30003. QoS 2(\u6b63\u597d\u4e00\u6b21\u4f20\u8f93)<\/strong>\uff1a<\/h3>\n\n\n\n
\n
\u3000\u3000\u4e09\u3001 QoS 2\u6a21\u5f0f\u4e0b\uff0c\u5982\u4f55\u5904\u7406\u63a5\u6536\u7aef\u786e\u8ba4\u4ee5\u786e\u4fdd\u6d88\u606f\u7684\u552f\u4e00\u6027?<\/h2>\n\n\n\n
\u3000\u3000\u56db\u3001 \u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0cMQTT\u6d88\u606f\u4f20\u9012\u7684\u6700\u4f73\u5b9e\u8df5\u548c\u6848\u4f8b\u7814\u7a76\u6709\u54ea\u4e9b?<\/h2>\n\n\n\n
\n
\u3000\u3000\u4e94\u3001 QoS\u7b49\u7ea7\u5bf9MQTT\u7f51\u7edc\u6027\u80fd\u7684\u5f71\u54cd\u6709\u54ea\u4e9b\u8be6\u7ec6\u5206\u6790\u6216\u7814\u7a76?<\/h2>\n\n\n\n
\n
\n