根据AWS文档,AWS IoT基本摄取订阅的QoS为1,这意味着确保已发送的每个消息至少被接收一次。
以下是订阅AWS IoT基本摄取主题的示例代码,QoS设置为1:
import boto3
import json
# Initialize AWS IoT client
client = boto3.client('iot-data')
# Define function to handle incoming message
def message_received(topic, payload):
print('Message received on topic: {0}. Payload: {1}'.format(topic, payload))
# Subscribe to topic
response = client.subscribe(
topic='my/ingest/topic',
qos=1, # QoS setting of 1
callback=message_received
)
# Print subscription status
print(response)