static async Task SafeCompleteMessageAsync(ServiceBusMessageActions messageActions, ServiceBusReceivedMessage message, Transaction committableTransaction, CancellationToken cancellationToken = default) { using (var scope = new TransactionScope(committableTransaction, TransactionScopeAsyncFlowOption.Enabled)) { await messageActions.CompleteMessageAsync(message, cancellationToken).ConfigureAwait(false); scope.Complete(); } }
public static async Task RunAsync( [ServiceBusTrigger(FirstQueueNameKey, AutoCompleteMessages = true)] ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions) { // we want to validate that this doesn't trigger an exception in the SDK since AutoComplete = true await messageActions.CompleteMessageAsync(message); _waitHandle1.Set(); }
public static async Task RunAsync( [ServiceBusTrigger(FirstQueueNameKey, AutoCompleteMessages = true)] ServiceBusReceivedMessage[] array, ServiceBusMessageActions messageActions) { string[] messages = array.Select(x => x.Body.ToString()).ToArray(); foreach (var msg in array) { await messageActions.CompleteMessageAsync(msg); } ServiceBusMultipleTestJobsBase.ProcessMessages(messages); }
public static async Task QueueNoSessions( [ServiceBusTrigger(FirstQueueNameKey)] ServiceBusReceivedMessage msg, ServiceBusMessageActions messageActions, CancellationToken cancellationToken, ILogger logger) { logger.LogInformation($"DrainModeValidationFunctions.QueueNoSessions: message data {msg.Body}"); _drainValidationPreDelay.Set(); await DrainModeHelper.WaitForCancellation(cancellationToken); Assert.True(cancellationToken.IsCancellationRequested); await messageActions.CompleteMessageAsync(msg); _drainValidationPostDelay.Set(); }
public async Task CanCompleteMessagesConcurrently() { var mockReceiver = new Mock <ServiceBusReceiver>(); mockReceiver.Setup(r => r.CompleteMessageAsync(It.IsAny <ServiceBusReceivedMessage>(), It.IsAny <CancellationToken>())) // simulate completing the message .Returns(async() => await Task.Delay(20)); var actions = new ServiceBusMessageActions(mockReceiver.Object); var tasks = new List <Task>(); for (int i = 0; i < 1000; i++) { tasks.Add(actions.CompleteMessageAsync(ServiceBusModelFactory.ServiceBusReceivedMessage())); } await Task.WhenAll(tasks); }
public static async Task Run( [ServiceBusTrigger("<queue_name>", Connection = "<connection_name>")] ServiceBusReceivedMessage[] messages, ServiceBusMessageActions messageActions) { foreach (ServiceBusReceivedMessage message in messages) { if (message.MessageId == "1") { await messageActions.DeadLetterMessageAsync(message); } else { await messageActions.CompleteMessageAsync(message); } } }
public static async Task TopicNoSessionsBatch( [ServiceBusTrigger(TopicNameKey, FirstSubscriptionNameKey)] ServiceBusReceivedMessage[] array, ServiceBusMessageActions messageActions, CancellationToken cancellationToken, ILogger logger) { Assert.True(array.Length > 0); logger.LogInformation($"DrainModeTestJobBatch.TopicNoSessionsBatch: received {array.Length} messages"); _drainValidationPreDelay.Set(); await DrainModeHelper.WaitForCancellation(cancellationToken); Assert.True(cancellationToken.IsCancellationRequested); foreach (ServiceBusReceivedMessage msg in array) { await messageActions.CompleteMessageAsync(msg); } _drainValidationPostDelay.Set(); }
public static async Task Run( [ServiceBusTrigger("<queue_name>", Connection = "<connection_name>", IsSessionsEnabled = true)] ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions, ServiceBusReceiveActions receiveActions) { if (message.MessageId == "1") { await messageActions.DeadLetterMessageAsync(message); } else { await messageActions.CompleteMessageAsync(message); // attempt to receive additional messages in this session await receiveActions.ReceiveMessagesAsync(maxMessages : 10); } }
public static async Task QueueWithSessions( [ServiceBusTrigger(FirstQueueNameKey, IsSessionsEnabled = true)] ServiceBusReceivedMessage msg, string sessionId, ServiceBusMessageActions messageActions, CancellationToken cancellationToken, ILogger logger) { logger.LogInformation( $"DrainModeValidationFunctions.QueueWithSessions: message data {msg.Body} with session id {msg.SessionId}"); Assert.AreEqual(_drainModeSessionId, msg.SessionId); Assert.AreEqual(msg.SessionId, sessionId); _drainValidationPreDelay.Set(); await DrainModeHelper.WaitForCancellation(cancellationToken); Assert.True(cancellationToken.IsCancellationRequested); await messageActions.CompleteMessageAsync(msg); _drainValidationPostDelay.Set(); }
public static async Task QueueWithSessionsBatch( [ServiceBusTrigger(FirstQueueNameKey, IsSessionsEnabled = true)] ServiceBusReceivedMessage[] array, ServiceBusMessageActions messageActions, CancellationToken cancellationToken, ILogger logger) { Assert.True(array.Length > 0); logger.LogInformation( $"DrainModeTestJobBatch.QueueWithSessionsBatch: received {array.Length} messages with session id {array[0].SessionId}"); Assert.AreEqual(_drainModeSessionId, array[0].SessionId); _drainValidationPreDelay.Set(); await DrainModeHelper.WaitForCancellation(cancellationToken); Assert.True(cancellationToken.IsCancellationRequested); foreach (ServiceBusReceivedMessage msg in array) { await messageActions.CompleteMessageAsync(msg); } _drainValidationPostDelay.Set(); }