问题描述
如何识别topic
的publish
是否成功.有什么方法可以使您对发布到某个主题有所认可.
How to identify whether the publish
to a topic
was success or not. Is there any way to get acknowledgement on publishing to a topic.
如果客户端之间在publish
期间(发布者/订阅者)如何处理它,则有任何连接丢失.
If there is any connection loss during publish
between the clients(Publisher/Subscriber) how to handle it.
我不希望订阅者在收到pay_load之后向发布端的特定主题发送确认消息.
I don't want the subscriber to send an ack to specific topic in the publishing end after receiving the pay_load.
这是我的红宝石代码:
假设,我已经创建了客户端(@client)
,并且在两边都进行了配置.
Assume, I have created clients(@client)
and configured on both sides.
def publish_it
@client.publish('test/hai', 'message')
# Ack the publish
end
订阅
@client.subscribe('test/#')
@client.get do |topic,message|
puts "#{topic}: #{message}"
end
推荐答案
MQTT中没有端到端(发布者到订阅者)的传递通知.这是因为作为pub/sub协议,发布者无法知道给定主题的订阅者数量,其范围可能是0到n.
There is no end to end (publisher to subscriber) delivery notification in MQTT. This is because as a pub/sub protocol there is no way for a publisher to know how many subscribers there are to a given topic, there could be anything from 0 to n.
规范中内置的QOS级别可确保将消息从发布者传递到代理(然后从代理传递给订户).如果要确保传递邮件,请使用QOS级别1或2.
The QOS levels built into the spec ensure that messages are delivered from the publisher to the broker (and then from the broker to the subscribers). If you want to ensure a message is delivered then use either QOS level 1 or 2.
QOS 1将确保至少发送一次消息(如果出现网络问题,则可能会发送更多消息)
QOS 1 will ensure a message is delivered at least once (possibly more if there are network problems)
QOS 2将确保仅发送一次消息.
QOS 2 will ensure a message is delivered only once.
在大多数MQTT客户端库中,还存在deliveryComplete
回调,一旦完成所有发布的QOS握手,就应调用该回调,如果您添加其中一个,则可以确信该消息已经发出.从发布者到经纪人.不幸的是,我看不到在Ruby客户端中实现了
In most of MQTT client libraries there is also the deliveryComplete
callback which should be called once all the QOS handshake for a publish has been completed, if you add one of these you can be reasonably confident that the message has made it from the publisher as far as the broker. Unfortunately I can't see this implemented in the Ruby client
这篇关于发布确认书-MQTT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!