Localstack和AWS SQS通过boto3接收消息返回不同的消息格式

时间:2019-11-21 20:52:46

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

我遇到一个问题(使用boto3,python和localstack),该消息格式在localstack和AWS的消息格式之间不同。我想知道我是否忽略了某些事情,我真的希望避免为SQS使用者使用两组不同的消息解析逻辑。

这是我发布到SNS主题的方式,然后将消息推送到SQS队列中

# Publish a simple message to the specified SNS topic
response = sns.publish(
    TopicArn=cfg.aws['sns_topic'],    
    Message='tacoPurchased',
    MessageAttributes = {
        'shell_type': {
            'DataType': 'String',
            'StringValue': 'soft'
        },
        'cheese': {
            'DataType': 'String',
            'StringValue': 'False'
        },
        'base': {
            'DataType': 'String',
            'StringValue': 'pork'
        },
        'extras': {
            'DataType': 'String',
            'StringValue': 'lettuce, cream_cheese'
        }
    }
)

这是不同于sqs队列接收消息的方式

Amazon SQS:


{u'Body': 'tacoPurchased', u'ReceiptHandle': 'AQEBquQzZY/tjknW3wgwH1yaJgMEbzDY8u+IsUYKpcSZ2lBzESfqfSkFuT6v9lMgiKH8YrtLdmADPL1cSKaCjDzWK9YTlHr6xvL1ZgWa8/vR+8s/+NaeuwdM6/Z3JkIPxkTKsws132M3za3KC0XfoabbYbp9EpUpFGlcZhacY1Fv/SLNw+LjiThcGC3fQD1qCQX7Dmq1+HrVhw4lFPC+SFX9yIN7/rcAe1rW+rQHubW4a1idPEv1FY8RzuDgwmMa3t4dF0KaAa3pZuzC9uOBh5c2Rj4KU5ExznUTqNcA8JZfuaPpBx+T4CZI0c+KaclyOrDXKJitGVwsxx1HKr5WCu8F06g0GTHn5eF0obfE0AgD++DlBzjs0ZAJM5Frv5Gp82LP5SdRjZUFKPTfa9E8pzU3mg==', u'MD5OfBody': '73c55f302c823ea1e6ec824b3b95eb7b', u'MD5OfMessageAttributes': 'e109406844f754d7b957d35f12993e7a', u'MessageId': 'fd405f0c-aa3e-44da-9dc2-d0e9edb8b55f', u'Attributes': {'SentTimestamp': '1574365120477'}, u'MessageAttributes': {'cheese': {u'DataType': 'String', u'StringValue': 'False'}, 'base': {u'DataType': 'String', u'StringValue': 'pork'}, 'shell_type': {u'DataType': 'String', u'StringValue': 'soft'}, 'extras': {u'DataType': 'String', u'StringValue': 'lettuce, cream_cheese'}}}

本地堆栈SQS:

{u'Body': '{"MessageId": "d23e7da9-f171-48b7-8689-ec3932d32b1d", "Type": "Notification", "Timestamp": "2019-11-21T20:00:39.036078Z", "Message": "tacoPurchased", "TopicArn": "arn:aws:sns:us-east-1:000000000000:reggora-topic", "MessageAttributes": {"cheese": {"Type": "String", "Value": "False"}, "base": {"Type": "String", "Value": "pork"}, "extras": {"Type": "String", "Value": "lettuce, cream_cheese"}, "shell_type": {"Type": "String", "Value": "soft"}}}', u'Attributes': {'SentTimestamp': '1574366439045'}, u'ReceiptHandle': '297122ad-fb97-4677-bbe5-46e35e0d1985#cb8a4098-7d19-4564-b824-99ca73c89e2e', u'MD5OfBody': '65046a5bd2e45d668e6c8be71cf84b47', u'MessageId': '297122ad-fb97-4677-bbe5-46e35e0d1985'}

0 个答案:

没有答案