amazon-web-services - 使用 QoS.EXACTLY_ONCE 订阅主题时使用 awsiotsdk,遇到 AWS_ERROR_MQTT_UNEXPECTED_HANGUP
问题描述
我正在关注pub/sub中的示例awsiotsdk
。
# boilerplate setup code omitted
self.mqtt_connection = awsiot.mqtt_connection_builder.websockets_with_default_aws_signing(...)
connect_future = self.mqtt_connection.connect()
print('Connected: ', connect_future.result())
[OUTPUT] Connected: {'session_present': True}
连接过程中的一切看起来都很好。接下来我订阅一个主题:
def mycallback(*args, **kwargs):
print("mycallback: ", args, kwargs)
subscribe_future, packet_id = self.mqtt_connection.subscribe(
topic='test/topic',
callback=mycallback,
qos=awscrt.mqtt.QoS.AT_LEAST_ONCE
)
subscribe_future.result()
上面的代码有效,我以后可以成功发布和接收消息。
但是,如果我将 QoS 更改为,则会EXACTLY_ONCE
出现以下错误:
In _on_connection_interrupted: (), {'connection': <awscrt.mqtt.Connection object at 0x7f804acfea40>, 'error': AwsCrtError(name='AWS_ERROR_MQTT_UNEXPECTED_HANGUP', message='The connection was closed unexpectedly.', code=5134)}
In _on_connection_resumed: (), {'connection': <awscrt.mqtt.Connection object at 0x7f804acfea40>, 'return_code': <ConnectReturnCode.ACCEPTED: 0>, 'session_present': True}
In _on_connection_interrupted: (), {'connection': <awscrt.mqtt.Connection object at 0x7f804acfea40>, 'error': AwsCrtError(name='AWS_ERROR_MQTT_UNEXPECTED_HANGUP', message='The connection was closed unexpectedly.', code=5134)}
In _on_connection_resumed: (), {'connection': <awscrt.mqtt.Connection object at 0x7f804acfea40>, 'return_code': <ConnectReturnCode.ACCEPTED: 0>, 'session_present': True}
<repeats a few more lines>
EXACTLY_ONCE 有什么问题?这似乎是我想要的 QoS。
解决方案
EXACTLY_ONCE
AWS IoT Core 服务器当前不支持(MQTT QOS 级别 2)。源代码中提到了这一点:
QoS 2 - Exactly once delivery
This is the highest quality of service, for use when neither loss nor
duplication of messages are acceptable. There is an increased overhead
associated with this quality of service.
Note that, while this client supports QoS 2, the AWS IoT Core server
does not support QoS 2 at time of writing (May 2020).
并在开发者指南中:
MQTT 协议定义了第三级 QoS,即 2 级,但 AWS IoT 不支持它。
推荐阅读
- flutter - 如何使用颤振将数据写入firebase数据库?
- javascript - Firebase:如何取回数组而不是对象
- c++ - C ++为什么在我的多维数组中超出范围时获得下一行值?
- python - 将多个字符串转换为数组
- python - 在 django 中使用 ariadne 时的文件夹设计
- python - 使用 ChromeDriverManager 时无法启动浏览器
- node.js - 如何在反应前端显示文件(图像)它们的名称从 mongoDb 获取并将它们存储在服务器上
- matplotlib - 在 Raspberry Pi 上卸载 matplotlib 时出现权限错误
- python - ValueError:请使用“Layer”实例初始化“TimeDistributed”层
- javascript - 该函数在以下代码中的工作方式