使用 mosca MQTT 请求响应模式 [英] Request response pattern with mosca MQTT
问题描述
是否有任何方法可以使用 mosca MQTT 实现请求-响应模式,以检查来自客户端的回复并重新发布,如果我在预期时间内没有收到预期回复".
我相信这在 Mqtt 5 中是可能的,但截至目前,我必须使用具有 QoS 1 的 Mosca 代理(支持直到 Mqtt 3.1.1)
我正在寻找一种 Node js 解决方法来实现这一点.
根据我的评论,您可以使用任何 MQTT 代理实现请求-响应模式,但是,在 v5 之前,您需要自己实现(或者有一个回复主题和消息 ID,或在每条消息中包含特定的回复主题).
因为 MQTT 3.11 本身不直接提供此功能,并且 MQTT 有效负载没有标准格式(只有一些字节!),所以不可能提出通用实现(在要求).这在 MQTT v5 中通过包含 属性 包括 响应主题 和 相关数据.对于早期版本,您不得不在有效负载中添加一些额外信息(使用您选择的任何编码机制).
有一些 Stack Overflow 问题可能会提供一些见解:
其他文章:
- Eclipse 库拉
- 股票浏览器
- 使用请求-响应模式和 MQTT 开发物联网应用(学术文章 - 需要购买才能阅读全文).
- 亚马逊设备影子 MQTT 主题(例如,向
$aws/things/thingName/shadow/get
发送消息,AWS IoT 在/get/accepted
或/get/rejected
上做出响应).
这里有几个节点包(注意:这些已经有一段时间没有更新了,我也没有查看代码):
即使使用 MQTT v5,您也需要自己实现空闲超时位.如果您使用的是 QOS 1/2,那么代理将负责重新发送消息(直到它收到 PUBACK/PUBCOMP),因此重新发送消息可能会适得其反(当通信链接关闭时,大量相同的消息排队)>
Is there any way to implement request-response pattern with mosca MQTT to "check reply from the client and re publish if i dont receive expected reply within expected time".
I believe this is possible in Mqtt 5, but as of now, I have to use Mosca broker with QoS 1(which support until Mqtt 3.1.1)
I am looking for a Node js workaround to achieve this.
As per my comment you can implement a request-response pattern with any MQTT broker but, prior to v5, you need to implement this yourself (either have a single reply-to topic and a message ID, or include a specific reply-to topic within each message).
Because MQTT 3.11 itself does not provide this functionality directly and there is no standard format for the MQTT payload (just some bytes!) its not possible to come up with a generic implementation (a unique id of some kind is needed within the request). This is resolved in MQTT v5 through the ability to include properties including Response Topic and Correlation Data. For earlier versions you are stuck with adding some extra information into the payload (using whatever encoding mechanism you choose).
There are a few Stack Overflow questions that might provide some insight:
Other articles:
- Eclipse Kura
- Stock Explorer
- IoT Application Development Using Request-Response Pattern with MQTT (Academic article - purchase needed to read whole thing).
- Amazon device shadow MQTT topics (e.g. send message to
$aws/things/thingName/shadow/get
and AWS IoT responds on/get/accepted
or/get/rejected
).
Here are a few node packages (note: these have not been updated for some time and I have not reviewed the code):
Even with MQTT v5 you would need to implement the idle timeout bit yourself. If you are using QOS 1/2 then the broker will take care of resending the message (until it receives a PUBACK/PUBCOMP) so resending the message may be counterproductive (lots of identical messages queued up while the comms link is down)
这篇关于使用 mosca MQTT 请求响应模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!