mosquitto的qos

MQTT defines three levels of Quality of Service (QoS). The QoS defines how hard the broker/client will try to ensure that a message is received. Messages may be sent at any QoS level, and clients may attempt to subscribe to topics at any QoS level. This means that the client chooses the maximum QoS it will receive. For example, if a message is published at QoS 2 and a client is subscribed with QoS 0, the message will be delivered to that client with QoS 0. If a second client is also subscribed to the same topic, but with QoS 2, then it will receive the same message but with QoS 2. For a second example, if a client is subscribed with QoS 2 and a message is published on QoS 0, the client will receive it on QoS 0.

Higher levels of QoS are more reliable, but involve higher latency and have higher bandwidth requirements.

0: The broker/client will deliver the message once, with no confirmation.

1: The broker/client will deliver the message at least once, with confirmation required.

2: The broker/client will deliver the message exactly once by using a four step handshake.
MQTT定义了三个级别的服务质量(QoS)。QoS定义了代理/客户端尝试确保消息被接收的难度。消息可以在任何QoS级别发送,客户端可以尝试订阅任何QoS级别的主题。这意味着客户端选择它将接收到的最大QoS。例如,如果消息以QoS 2发布,而客户端以QoS 0订阅,则消息将被发送到具有QoS 0的客户端。如果第二个客户端也订阅了相同的主题,但具有QoS 2,那么它将接收相同的消息,但具有QoS 2。对于第二个示例,如果客户端订阅了QoS 2,并且在QoS 0上发布了消息,则该客户端将在QoS 0上接收该消息。

更高级别的QoS更可靠,但涉及更高的延迟和更高的带宽需求。

0:代理/客户端只传递一次消息,不需要确认。

1:代理/客户端将至少传递一次消息,并需要确认。

2:代理/客户端将通过使用四步握手来准确地传递消息一次。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在使用Spring Boot开发MQTT应用程序时,可以使用Eclipse Paho MQTT客户端库来连接Mosquitto Broker。MQTT协议支持三种不同的服务质量(QoS)级别: 1. QoS 0:最多一次传输,消息发布者将消息发送到MQTT服务器,然后将消息传递给所有订阅了相应主题的客户端。如果消息在传输过程中丢失,则不会重试。 2. QoS 1:至少一次传输,在QoS 1级别下,发布者将消息发送到MQTT服务器,等待服务器确认后再将消息传递给所有订阅了相应主题的客户端。如果消息丢失或未收到确认,则会重试。 3. QoS 2:恰好一次传输,发布者将消息发送到MQTT服务器,等待服务器向其发送确认后再将消息传递给所有订阅了相应主题的客户端。如果消息丢失或未收到确认,则会重试。 在Spring Boot中,可以使用Spring Integration和Spring Messaging来实现MQTT应用程序的开发。可以使用spring-integration-mqtt库来实现与Mosquitto Broker的连接。在使用spring-integration-mqtt库时,可以通过配置QoS级别来控制消息传输的可靠性。例如,可以在MQTT消息处理器上设置QoS级别,如下所示: ``` @Bean public MessageHandler mqttOutbound() { MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler("clientId", mqttClientFactory()); messageHandler.setAsync(true); messageHandler.setDefaultTopic("testTopic"); messageHandler.setDefaultQos(1); // 设置QoS级别为1 return messageHandler; } ``` 在上面的示例中,设置了默认的QoS级别为1。这意味着消息将至少传输一次,并等待服务器确认后再传递给所有订阅了相应主题的客户端。可以根据具体应用程序的需求来选择合适的QoS级别。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值