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


C# SubscriptionClient.ReceiveAsync方法代码示例

本文整理汇总了C#中SubscriptionClient.ReceiveAsync方法的典型用法代码示例。如果您正苦于以下问题:C# SubscriptionClient.ReceiveAsync方法的具体用法?C# SubscriptionClient.ReceiveAsync怎么用?C# SubscriptionClient.ReceiveAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SubscriptionClient的用法示例。


在下文中一共展示了SubscriptionClient.ReceiveAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartAsync

        protected override async Task StartAsync()
        {
            InfoLogging(string.Format("{0} - Processing", SubscriptionName));

            _subClient = await _clientFactory.CreateSubscriptionClientAsync(TopicName, SubscriptionName).ConfigureAwait(false);
            
            _retryStrategy = CreateRetryPolicy(MessageRepostMaxCount);
            var stopWatch = new Stopwatch();

            while (!Token.IsCancellationRequested)
            {
                var message = await _subClient.ReceiveAsync(new TimeSpan(0, 0, 10)).ConfigureAwait(false);
                if (message == null) continue;

                var messageBody = message.GetBody<string>();
                if (String.IsNullOrEmpty(messageBody)) continue;

                var messageId = message.MessageId;
                message.Complete();

                DebugLogging(string.Format("{0} - Received new message", SubscriptionName), messageId);
                var failed = false;
                stopWatch.Restart();

                try
                {
                    await _retryStrategy.ExecuteAsync(() =>
                        Do(messageBody), Token).ConfigureAwait(false);

                    stopWatch.Stop();
                    var timeSpan = stopWatch.Elapsed;
                    DebugLogging(string.Format("{0} - Processed message",
                        SubscriptionName), messageId,
                        timeSpan.TotalSeconds);
                }
                catch (Exception exception)
                {
                    ErrorLogging("Message processing failed after retry, posting as failed message.", messageId,
                        exception);
                    failed = true;
                }

                if (failed)
                    await HandleFailedMessageAsync(messageBody).ConfigureAwait(false);
            }
        }
开发者ID:proactima,项目名称:AzureWorkers,代码行数:46,代码来源:BaseServiceBusTopicWorker.cs

示例2: ProcessGetAsync

		private async Task<IEnumerable<string>> ProcessGetAsync(SubscriptionClient client)
		{
			var result = new List<string>();
			var watch = new Stopwatch();
			for (int i = 1; i < 11; i++)
			{
				watch.Restart();
				BrokeredMessage message = await client.ReceiveAsync(new TimeSpan(0, 0, 5));
				watch.Stop();
				result.Add($"Azure Service Bus Topic {i} try: {watch.ElapsedMilliseconds}");
			}
			return result;
		}
开发者ID:Neonsonne,项目名称:dbSpeed,代码行数:13,代码来源:AzureServiceBusTopicController.cs


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