public async Task Purge() { await using (var context = new AzureMessagingContext(QueueUrl)) { var receiver = context.Purger; while (await receiver.PeekMessageAsync() != null) { await receiver.ReceiveMessagesAsync(MaxNumberOfMessages); } } }
public async Task <string> Publish(string message) { await Limiter.Add(1); await using (var context = new AzureMessagingContext(QueueUrl)) { var msg = new azureMessaging.ServiceBusMessage(message); await context.Sender.SendMessageAsync(msg); return(msg.MessageId); } }
public async Task <IEnumerable <QueueMessageHandle> > PullBatch(int timeoutSeconds = 10, int?maxNumerOfMessages = null) { var result = new List <QueueMessageHandle>(); await using (var context = new AzureMessagingContext(QueueUrl)) { var receiver = context.Receiver; foreach (var message in await receiver.ReceiveMessagesAsync(MaxNumberOfMessages, timeoutSeconds.Seconds())) { result.Add(new QueueMessageHandle(message.Body.ToString(), message.MessageId, () => Task.CompletedTask)); } } return(result); }
public async Task <IEnumerable <string> > PublishBatch(IEnumerable <string> messages, int retry = 0) { await Limiter.Add(messages.Count()); await using (var context = new AzureMessagingContext(QueueUrl)) { var batch = await context.Sender.CreateMessageBatchAsync(); var messageObjects = messages.Select(c => new azureMessaging.ServiceBusMessage(c)).ToArray(); messageObjects.Do(m => batch.TryAddMessage(m)); await context.Sender.SendMessagesAsync(batch); return(messageObjects.Select(c => c.MessageId)); } }