本文整理汇总了C#中Amazon.SQS.AmazonSQSClient.SendMessageBatch方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonSQSClient.SendMessageBatch方法的具体用法?C# AmazonSQSClient.SendMessageBatch怎么用?C# AmazonSQSClient.SendMessageBatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amazon.SQS.AmazonSQSClient
的用法示例。
在下文中一共展示了AmazonSQSClient.SendMessageBatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SQSSendMessageBatch
public static void SQSSendMessageBatch()
{
#region SQSSendMessageBatch
var client = new AmazonSQSClient();
var entry1 = new SendMessageBatchRequestEntry
{
DelaySeconds = 0,
Id = "Entry1",
MessageAttributes = new Dictionary<string, MessageAttributeValue>
{
{
"MyNameAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "John Doe" }
},
{
"MyAddressAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "123 Main St." }
},
{
"MyRegionAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "Any Town, United States" }
}
},
MessageBody = "John Doe customer information."
};
var entry2 = new SendMessageBatchRequestEntry
{
DelaySeconds = 0,
Id = "Entry2",
MessageAttributes = new Dictionary<string, MessageAttributeValue>
{
{
"MyNameAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "Jane Doe" }
},
{
"MyAddressAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "456 Center Road" }
},
{
"MyRegionAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "Any City, United States" }
}
},
MessageBody = "Jane Doe customer information."
};
var entry3 = new SendMessageBatchRequestEntry
{
DelaySeconds = 0,
Id = "Entry3",
MessageAttributes = new Dictionary<string, MessageAttributeValue>
{
{
"MyNameAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "Richard Doe" }
},
{
"MyAddressAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "789 East Blvd." }
},
{
"MyRegionAttribute", new MessageAttributeValue
{ DataType = "String", StringValue = "Anywhere, United States" }
}
},
MessageBody = "Richard Doe customer information."
};
var request = new SendMessageBatchRequest
{
Entries = new List<SendMessageBatchRequestEntry>() { entry1, entry2, entry3 },
QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue"
};
var response = client.SendMessageBatch(request);
if (response.Successful.Count > 0)
{
Console.WriteLine("Successfully sent:");
foreach (var success in response.Successful)
{
Console.WriteLine(" For ID: '" + success.Id + "':");
Console.WriteLine(" Message ID = " + success.MessageId);
Console.WriteLine(" MD5 of message attributes = " +
success.MD5OfMessageAttributes);
Console.WriteLine(" MD5 of message body = " +
success.MD5OfMessageBody);
}
}
if (response.Failed.Count > 0)
{
Console.WriteLine("Failed to be sent:");
foreach (var fail in response.Failed)
{
//.........这里部分代码省略.........
示例2: QueueMessages
private static void QueueMessages(int count)
{
using (AmazonSQSClient client = new AmazonSQSClient(
ConfigurationManager.AppSettings["AWSAccessKey"],
ConfigurationManager.AppSettings["AWSSecretAccessKey"]))
{
Parallel.ForEach(Partitioner.Create(0, count), (range) =>
{
SendMessageBatchRequest request = new SendMessageBatchRequest();
request.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
int numberOfMessages = range.Item2 - range.Item1;
for (int i = 0; i < numberOfMessages; i++)
{
request.Entries.Add(new SendMessageBatchRequestEntry() { Id = i.ToString(), MessageBody = i.ToString() });
if ((request.Entries.Count == 10) |
(i == numberOfMessages - 1))
{
client.SendMessageBatch(request);
request.Entries.Clear();
}
}
});
}
}