public static async Task QueueWithSessionsBatch(
                [ServiceBusTrigger(FirstQueueNameKey, IsSessionsEnabled = true)]
                ServiceBusReceivedMessage[] array,
                string[] sessionIdArray,
                ServiceBusSessionMessageActions sessionActions,
                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);
                int index = 0;

                foreach (ServiceBusReceivedMessage msg in array)
                {
                    Assert.AreEqual(msg.SessionId, sessionIdArray[index++]);
                    // validate that manual lock renewal works
                    var initialLockedUntil = sessionActions.SessionLockedUntil;
                    await sessionActions.RenewSessionLockAsync();

                    Assert.Greater(sessionActions.SessionLockedUntil, initialLockedUntil);

                    await sessionActions.CompleteMessageAsync(msg);
                }

                _drainValidationPostDelay.Set();
            }
Exemple #2
0
            public static async Task RunAsync(
                [ServiceBusTrigger(FirstQueueNameKey, IsSessionsEnabled = true)]
                ServiceBusReceivedMessage[] messages,
                ServiceBusSessionMessageActions sessionActions,
                ServiceBusClient client)
            {
                using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    await sessionActions.CompleteMessageAsync(messages.First());

                    var sender = client.CreateSender(_secondQueueScope.QueueName);
                    await sender.SendMessageAsync(new ServiceBusMessage()
                    {
                        SessionId = "sessionId"
                    });

                    ts.Complete();
                }
                // This can be uncommented once https://github.com/Azure/azure-sdk-for-net/issues/24989 is fixed
                // ServiceBusReceiver receiver1 = await client.AcceptNextSessionAsync(_firstQueueScope.QueueName);
                // Assert.IsNull(receiver1);
                // need to use a separate client here to do the assertions
                var noTxClient = new ServiceBusClient(ServiceBusTestEnvironment.Instance.ServiceBusConnectionString);
                ServiceBusReceiver receiver2 = await noTxClient.AcceptNextSessionAsync(_secondQueueScope.QueueName);

                Assert.IsNotNull(receiver2);
                _waitHandle1.Set();
            }
Exemple #3
0
            public static async Task TopicWithSessions(
                [ServiceBusTrigger(TopicNameKey, FirstSubscriptionNameKey, IsSessionsEnabled = true)]
                ServiceBusReceivedMessage msg,
                ServiceBusSessionMessageActions messageSession,
                CancellationToken cancellationToken,
                ILogger logger)
            {
                logger.LogInformation(
                    $"DrainModeValidationFunctions.TopicWithSessions: message data {msg.Body} with session id {msg.SessionId}");
                Assert.AreEqual(_drainModeSessionId, msg.SessionId);
                _drainValidationPreDelay.Set();
                await DrainModeHelper.WaitForCancellation(cancellationToken);

                Assert.True(cancellationToken.IsCancellationRequested);
                await messageSession.CompleteMessageAsync(msg);

                _drainValidationPostDelay.Set();
            }
        public static async Task Run(
            [ServiceBusTrigger("<queue_name>", Connection = "<connection_name>", IsSessionsEnabled = true)]
            ServiceBusReceivedMessage[] messages,
            ServiceBusSessionMessageActions sessionActions)
        {
            foreach (ServiceBusReceivedMessage message in messages)
            {
                if (message.MessageId == "1")
                {
                    await sessionActions.DeadLetterMessageAsync(message);
                }
                else
                {
                    await sessionActions.CompleteMessageAsync(message);
                }
            }

            // We can also perform session-specific operations using the actions, such as setting state that is specific to this session.
            await sessionActions.SetSessionStateAsync(new BinaryData("<session state>"));
        }
Exemple #5
0
            public static async Task TopicWithSessionsBatch(
                [ServiceBusTrigger(TopicNameKey, FirstSubscriptionNameKey, IsSessionsEnabled = true)]
                ServiceBusReceivedMessage[] array,
                ServiceBusSessionMessageActions messageSession,
                CancellationToken cancellationToken,
                ILogger logger)
            {
                Assert.True(array.Length > 0);
                logger.LogInformation(
                    $"DrainModeTestJobBatch.TopicWithSessionsBatch: 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 messageSession.CompleteMessageAsync(msg);
                }

                _drainValidationPostDelay.Set();
            }