Evg*_*eny 6 amazon-sqs amazon-web-services amazon-sns
AWS SNS和SQS的文档包含有关消息属性的部分.但是,当该队列订阅了SNS主题时,没有解释如何获得SQS 消息属性.
有没有办法配置AWS SNS以将特定消息属性添加到通过订阅发送的SQS消息?
Bor*_*lov 10
从aws文档:
要将消息属性与Amazon SQS端点一起使用,必须将订阅属性Raw Message Delivery设置为True.有关原始邮件传递的详细信息,请参阅附录:大型有效负载和原始邮件传递. 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"}}'
Run Code Online (Sandbox Code Playgroud)
启用原始传递为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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然使用Amazon SNS消息属性的文档发送亚马逊SNS消息属性亚马逊SQS,看来该属性在发送体的消息,而不是附着在所得亚马逊SQS消息作为消息属性.
例如,我做了以下事情:
我通过AWS命令行界面(CLI)发布:
aws sns publish --topic-arn arn:aws:sns:ap-southeast-2:123456789012:foo --message msg --subject subj --message-attributes '{"somename" : { "DataType":"String", "StringValue":"somevalue"}}'
Run Code Online (Sandbox Code Playgroud)
(我从aws cli中的map数据类型获得了语法帮助)
SQS中生成的消息将属性显示为消息的一部分:
{
"Type" : "Notification",
"MessageId" : "53e3adad-723a-5eae-a7b7-fc0468ec2d37",
"TopicArn" : "arn:aws:sns:ap-southeast-2:123456789012:foo",
"Subject" : "subj",
"Message" : "msg",
"Timestamp" : "2017-05-29T12:48:22.186Z",
...
"MessageAttributes" : {
"somename" : {"Type":"String","Value":"somevalue"}
}
}
Run Code Online (Sandbox Code Playgroud)
如果将这些属性作为官方SQS属性附加到SQS消息,那将会更好.唉,似乎情况并非如此.
归档时间: |
|
查看次数: |
7343 次 |
最近记录: |