예제 #1
0
        public async Task PluginsCanAlterMessage(bool schedule)
        {
            await using var scope = await ServiceBusScope.CreateWithQueue(
                            enablePartitioning : false,
                            enableSession : false);

            var plugin  = new SendReceivePlugin();
            var options = new ServiceBusClientOptions();

            options.AddPlugin(plugin);
            var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);

            var sender   = client.CreateSender(scope.QueueName);
            var receiver = client.CreateReceiver(scope.QueueName);

            if (schedule)
            {
                await sender.ScheduleMessageAsync(new ServiceBusMessage(), DateTimeOffset.UtcNow);
            }
            else
            {
                await sender.SendMessageAsync(new ServiceBusMessage());
            }

            Assert.True(plugin.WasCalled);
            var receivedMessage = await receiver.ReceiveMessageAsync();

            Assert.AreEqual("received", receivedMessage.Body.ToString());
        }
예제 #2
0
        public async Task PluginsCanAlterMessageUsingSessionProcessor()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(
                             enablePartitioning: false,
                             enableSession: true))
            {
                var plugin  = new SendReceivePlugin();
                var options = new ServiceBusClientOptions();
                options.AddPlugin(plugin);
                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                var sender = client.CreateSender(scope.QueueName);

                await sender.SendMessageAsync(GetMessage("sessionId"));

                Assert.True(plugin.WasCalled);
                var processor = client.CreateSessionProcessor(scope.QueueName, new ServiceBusSessionProcessorOptions
                {
                    MaxConcurrentSessions = 1
                });
                processor.ProcessErrorAsync += ExceptionHandler;
                var tcs = new TaskCompletionSource <bool>();
                processor.ProcessMessageAsync += args =>
                {
                    Assert.AreEqual("received", args.Message.Body.ToString());
                    tcs.SetResult(true);
                    return(Task.CompletedTask);
                };
                await processor.StartProcessingAsync();

                await tcs.Task;
                await processor.StopProcessingAsync();
            }
        }
예제 #3
0
        public async Task PluginsCanAlterTopicSessionMessage()
        {
            await using (var scope = await ServiceBusScope.CreateWithTopic(
                             enablePartitioning: false,
                             enableSession: true))
            {
                var plugin  = new SendReceivePlugin();
                var options = new ServiceBusClientOptions();
                options.AddPlugin(plugin);
                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);
                var sender = client.CreateSender(scope.TopicName);

                await sender.SendMessageAsync(GetMessage("sessionId"));

                Assert.True(plugin.WasCalled);
                var receiver = await client.CreateSessionReceiverAsync(scope.TopicName, scope.SubscriptionNames.First());

                var receivedMessage = await receiver.ReceiveMessageAsync();

                Assert.AreEqual("received", receivedMessage.Body.ToString());
            }
        }
예제 #4
0
        public async Task PluginsCanAlterSessionMessage()
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(
                             enablePartitioning: false,
                             enableSession: true))
            {
                var plugin  = new SendReceivePlugin();
                var options = new ServiceBusClientOptions();
                options.AddPlugin(plugin);
                var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential, options);
                var sender = client.CreateSender(scope.QueueName);

                await sender.SendMessageAsync(GetMessage("sessionId"));

                Assert.True(plugin.WasCalled);
                var receiver = await client.CreateSessionReceiverAsync(scope.QueueName);

                var receivedMessage = await receiver.ReceiveMessageAsync();

                Assert.AreEqual("received", receivedMessage.Body.ToString());
            }
        }
예제 #5
0
        public async Task PluginsCanAlterSetOfMessages(bool schedule)
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(
                             enablePartitioning: false,
                             enableSession: false))
            {
                var plugin  = new SendReceivePlugin();
                var options = new ServiceBusClientOptions();
                options.AddPlugin(plugin);
                var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString, options);

                var sender      = client.CreateSender(scope.QueueName);
                var receiver    = client.CreateReceiver(scope.QueueName);
                int numMessages = 5;
                if (schedule)
                {
                    await sender.ScheduleMessagesAsync(GetMessages(numMessages), DateTimeOffset.UtcNow);
                }
                else
                {
                    await sender.SendMessagesAsync(GetMessages(numMessages));
                }

                Assert.True(plugin.WasCalled);

                var remaining = numMessages;
                while (remaining > 0)
                {
                    var receivedMessages = await receiver.ReceiveMessagesAsync(remaining);

                    remaining = -receivedMessages.Count;
                    foreach (var receivedMessage in receivedMessages)
                    {
                        Assert.AreEqual("received", receivedMessage.Body.ToString());
                    }
                }
            }
        }