且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在C#中访问Amazon SQS消息属性

更新时间:2023-11-25 13:41:16

好,所以我想到了这一点. 在进行调用以提取消息之前,需要将属性名称指定为ReceiveMessageRequest对象的属性.

Ok so I figured this one out. The attribute names need to be specified as a property of the ReceiveMessageRequest object before the call is made to pull the message.

因此,上面的代码需要更改为:

So, the code above needs to change to:

IAmazonSQS sqs = AWSClientFactory.CreateAmazonSQSClient();
ReceiveMessageResponse receiveMessage = new ReceiveMessageResponse();
ReceiveMessageRequest request = new ReceiveMessageRequest();

//Specify attribute list
List<string> AttributesList = new List<string>();
AttributesList.Add("MESSAGEPRIORITY");

//Assign list and QueueURL to request
request.MessageAttributeNames = AttributesList;
request.QueueUrl = "myURL";

//Receive the message...
receiveMessage = sqs.ReceiveMessage(request);
//Body...
string messageBody = receiveMessage.Messages[0].Body;
//...and attributes
Dictionary<string, MessageAttributeValue> messageAttributes = receiveMessage.Messages[0].MessageAttributes;

以上对我有用.希望它将对某人有用....

The above works for me. Hopefully it'll be useful to someone....