本文整理汇总了C#中Factory.ReceiveMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.ReceiveMessage方法的具体用法?C# Factory.ReceiveMessage怎么用?C# Factory.ReceiveMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factory
的用法示例。
在下文中一共展示了Factory.ReceiveMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveMessages
/// <summary>
/// Gets messages from an SQS queue.
/// </summary>
/// <param name="queueUrl">The sqs queue endpoint to get the messages from.</param>
/// <param name="maxMessages">The maximum number of messages to return (max 10)</param>
/// <param name="visibilityTimeout">The number of minutes to hide the message from other consumers for (max 12 hours or 720 minutes)</param>
/// <returns></returns>
public static Amazon.SQS.Model.ReceiveMessageResponse ReceiveMessages(string queueUrl, int maxMessages = 10, int visibilityTimeout = 0)
{
// Check for the maximum number of messages to get.
if (maxMessages > 10)
throw new ArgumentException("The maximum number of messages that can be returned is 10");
// Check that the visibility timeout is okay.
if (visibilityTimeout > 720)
throw new ArgumentException("The maximum amount of time that the message can be hidden for is 12 hours.");
// Get the messages from the queue.
Amazon.SQS.Model.ReceiveMessageResponse response = new Amazon.SQS.Model.ReceiveMessageResponse();
using (Amazon.SQS.IAmazonSQS client = new Factory().SQSClient())
{
Amazon.SQS.Model.ReceiveMessageRequest request = new Amazon.SQS.Model.ReceiveMessageRequest()
{
QueueUrl = queueUrl,
MaxNumberOfMessages = maxMessages
};
if (visibilityTimeout > 0)
{
request.VisibilityTimeout = visibilityTimeout;
}
response = client.ReceiveMessage(request);
}
return response;
}