gpt4 book ai didi

amazon-web-services - 如何在 SNS 订阅中添加 SQS 消息属性?

转载 作者:行者123 更新时间:2023-12-04 13:05:47 25 4
gpt4 key购买 nike

AWS SNS 和 SQS 的文档有关于消息属性的部分。但是没有解释当该队列订阅 SNS 主题时如何拥有 SQS 消息属性。

有没有办法配置 AWS SNS 以向通过订阅发送的 SQS 消息添加特定的消息属性?

最佳答案

从 aws 文档:

To use message attributes with Amazon SQS endpoints, you must set the subscription attribute, Raw Message Delivery, to True. For more information about raw message delivery, see Appendix: Large Payload and Raw Message Delivery. https://docs.aws.amazon.com/sns/latest/dg/SNSMessageAttributes.html https://docs.aws.amazon.com/sns/latest/dg/large-payload-raw-message.html



添加了来自现实项目的示例。希望它有助于澄清事情。
发布到 sns 主题的消息如下:
aws sns publish --topic-arn arn:aws:sns:us-west-2:xxx:pollution-event --message '{"operatorId":3375001,"eventTypeId":1,"eventLevelId":1,"validFrom":"2018-03-10T09:00:00Z","validTo":"2018-03-11T09:00:00Z"}'  --message-attributes '{"Type" : { "DataType":"String", "StringValue":"Orchestration.Services.Model.Pollution.PollutionMessage"}}'

启用原始交付为 false(默认) . sqs收到的消息只有内容,没有属性
{
"Type": "Notification",
"MessageId": "78d5bc6f-142c-5060-a75c-ef29b774ec66",
"TopicArn": "arn:aws:sns:eu-west-2:xxx:pollution-event",
"Message": "{\"validFrom\": \"2018-03-10T09:00:00Z\",\"validTo\": \"2018-03-11T09:00:00Z\",\"eventLevelId\": 1,\"eventTypeId\": 1,\"operatorId\": 3375001}",
"Timestamp": "2018-04-17T11:33:44.770Z",
"SignatureVersion": "1",
"Signature": "xxx==",
"SigningCertURL": "https://sns.eu-west-2.amazonaws.com/SimpleNotificationService-xxx.pem",
"UnsubscribeURL": "https://sns.eu-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-2:xxx",
"MessageAttributes": {
"Type": {
"Type": "String",
"Value": "Orchestration.Services.Model.Pollution.PollutionMessage"
},
"AWS.SNS.MOBILE.MPNS.Type": {
"Type": "String",
"Value": "token"
},
"AWS.SNS.MOBILE.MPNS.NotificationClass": {
"Type": "String",
"Value": "realtime"
},
"AWS.SNS.MOBILE.WNS.Type": {
"Type": "String",
"Value": "wns/badge"
}
}
}

There are no message attributes, it is contained within the message itself

启用原始交付为真。 消息包含消息属性和适当的内容
Message has an attribute
The attribute contains expected value

关于amazon-web-services - 如何在 SNS 订阅中添加 SQS 消息属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44238656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com