当前位置: 首页>>代码示例>>C#>>正文


C# Factory.ReceiveMessage方法代码示例

本文整理汇总了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;
        }
开发者ID:WOLAS-Revolution,项目名称:aws-tools,代码行数:36,代码来源:SQS.cs


注:本文中的Factory.ReceiveMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。