【问题标题】:How to set the SQS message class in boto3?boto3中如何设置SQS消息类?
【发布时间】:2018-07-22 23:02:53
【问题描述】:

我正在从 boto 迁移到 boto3。

下面的sn -p 将消息类设置为我的sqs:

conn = boto.sqs.connect_to_region(my_region)
queue = conn.create_queue(queue_name)
queue.set_message_class(boto.sqs.message.RawMessage)

如何用 boto3 做到这一点?

【问题讨论】:

    标签: python amazon-web-services boto boto3 amazon-sqs


    【解决方案1】:

    您需要创建SQS Client 并使用它。您不再需要设置RawMessage 类。

    import boto3
    client = boto3.client('sqs')
    response = client.send_message(
        QueueUrl='string',
        MessageBody='string',
        DelaySeconds=123,
        MessageAttributes={
            'string': {
                'StringValue': 'string',
                'BinaryValue': b'bytes',
                'StringListValues': [
                    'string',
                ],
                'BinaryListValues': [
                    b'bytes',
                ],
                'DataType': 'string'
            }
        },
        MessageDeduplicationId='string',
        MessageGroupId='string'
    )
    

    来源:https://boto3.readthedocs.io/en/latest/reference/services/sqs.html#SQS.Client.send_message

    【讨论】:

    • 谢谢@Asdfg,这是正确答案。正如您所指出的,在任何地方都没有提到设置 RawMessage 类,所以我推断我可以跳过这一步。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    • 2021-08-10
    • 2018-10-11
    • 2021-02-12
    • 1970-01-01
    • 2022-11-22
    • 2018-09-24
    相关资源
    最近更新 更多