本文整理汇总了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);
}
}
示例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;
}