本文整理汇总了C#中MessagingFactory.CreateMessageReceiverAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MessagingFactory.CreateMessageReceiverAsync方法的具体用法?C# MessagingFactory.CreateMessageReceiverAsync怎么用?C# MessagingFactory.CreateMessageReceiverAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagingFactory
的用法示例。
在下文中一共展示了MessagingFactory.CreateMessageReceiverAsync方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PickUpAndFixDeadletters
async Task PickUpAndFixDeadletters(MessagingFactory receiverFactory, string queueName, MessageSender resubmitSender, CancellationToken cancellationToken)
{
var doneReceiving = new TaskCompletionSource<bool>();
var dlqReceiver = await receiverFactory.CreateMessageReceiverAsync(QueueClient.FormatDeadLetterPath(queueName), ReceiveMode.PeekLock);
// close the receiver and factory when the CancellationToken fires
cancellationToken.Register(
async () =>
{
await dlqReceiver.CloseAsync();
doneReceiving.SetResult(true);
});
// register the OnMessageAsync callback
dlqReceiver.OnMessageAsync(
async message =>
{
var resubmitMessage = message.Clone();
if (resubmitMessage.Label != null && resubmitMessage.Label.Equals("Physicist"))
{
lock (Console.Out)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(
"\t\tFixing: \n\t\t\tMessageId = {0}, \n\t\t\tSequenceNumber = {1}, \n\t\t\tLabel = {2}",
message.MessageId,
message.SequenceNumber,
message.Label);
Console.ResetColor();
}
resubmitMessage.Label = "Scientist";
await resubmitSender.SendAsync(resubmitMessage);
}
await message.CompleteAsync();
},
new OnMessageOptions { AutoComplete = true, MaxConcurrentCalls = 1 });
await doneReceiving.Task;
}
示例2: ExceedMaxDelivery
async Task ExceedMaxDelivery(MessagingFactory receiverFactory, string queueName)
{
var receiver = await receiverFactory.CreateMessageReceiverAsync(queueName, ReceiveMode.PeekLock);
while(true)
{
var msg = await receiver.ReceiveAsync(TimeSpan.Zero);
if (msg != null)
{
Console.WriteLine("Picked up message; DeliveryCount {0}", msg.DeliveryCount);
await msg.AbandonAsync();
}
else
{
break;
}
}
var deadletterReceiver = await receiverFactory.CreateMessageReceiverAsync(QueueClient.FormatDeadLetterPath(queueName), ReceiveMode.PeekLock);
while (true)
{
var msg = await deadletterReceiver.ReceiveAsync(TimeSpan.Zero);
if (msg != null)
{
Console.WriteLine("Deadletter message:");
foreach (var prop in msg.Properties)
{
Console.WriteLine("{0}={1}", prop.Key, prop.Value);
}
await msg.CompleteAsync();
}
else
{
break;
}
}
}
示例3: ReceiveMessagesAsync
async Task ReceiveMessagesAsync(MessagingFactory receiverFactory, string queueName, CancellationToken cancellationToken)
{
var doneReceiving = new TaskCompletionSource<bool>();
var receiver = await receiverFactory.CreateMessageReceiverAsync(queueName, ReceiveMode.PeekLock);
// close the receiver and factory when the CancellationToken fires
cancellationToken.Register(
async () =>
{
await receiver.CloseAsync();
doneReceiving.SetResult(true);
});
// register the OnMessageAsync callback
receiver.OnMessageAsync(
async message =>
{
if (message.Label != null &&
message.ContentType != null &&
message.Label.Equals("Scientist", StringComparison.InvariantCultureIgnoreCase) &&
message.ContentType.Equals("application/json", StringComparison.InvariantCultureIgnoreCase))
{
var body = message.GetBody<Stream>();
dynamic scientist = JsonConvert.DeserializeObject(new StreamReader(body, true).ReadToEnd());
lock (Console.Out)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(
"\t\t\t\tMessage received: \n\t\t\t\t\t\tMessageId = {0}, \n\t\t\t\t\t\tSequenceNumber = {1}, \n\t\t\t\t\t\tEnqueuedTimeUtc = {2}," +
"\n\t\t\t\t\t\tExpiresAtUtc = {5}, \n\t\t\t\t\t\tContentType = \"{3}\", \n\t\t\t\t\t\tSize = {4}, \n\t\t\t\t\t\tContent: [ firstName = {6}, name = {7} ]",
message.MessageId,
message.SequenceNumber,
message.EnqueuedTimeUtc,
message.ContentType,
message.Size,
message.ExpiresAtUtc,
scientist.firstName,
scientist.name);
Console.ResetColor();
}
await message.CompleteAsync();
}
else
{
await message.DeadLetterAsync("ProcessingError", "Don't know what to do with this message");
}
},
new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1 });
await doneReceiving.Task;
}
示例4: RunResultsReceiver
static async Task<MessageReceiver> RunResultsReceiver(MessagingFactory receiverMessagingFactory)
{
// this receiver reads from the results queue and prints out the message
var receiver = await receiverMessagingFactory.CreateMessageReceiverAsync(SagaResultQueueName);
receiver.OnMessage(PrintResultMessage, new OnMessageOptions {AutoComplete = true});
return receiver;
}