async Task Multiple_plugins_should_be_able_to_manipulate_message() { var messageSender = new MessageSender(TestUtility.NamespaceConnectionString, TestConstants.NonPartitionedQueueName); var messageReceiver = new MessageReceiver(TestUtility.NamespaceConnectionString, TestConstants.NonPartitionedQueueName, ReceiveMode.ReceiveAndDelete); try { var sendReceivePlugin = new SendReceivePlugin(); messageSender.RegisterPlugin(sendReceivePlugin); messageReceiver.RegisterPlugin(sendReceivePlugin); var sendMessage = new Message(Encoding.UTF8.GetBytes("Test message")) { MessageId = Guid.NewGuid().ToString() }; await messageSender.SendAsync(sendMessage); // Ensure the plugin is called. Assert.True(sendReceivePlugin.MessageBodies.ContainsKey(sendMessage.MessageId)); var receivedMessage = await messageReceiver.ReceiveAsync(TimeSpan.FromMinutes(1)); Assert.Equal(sendMessage.Body, receivedMessage.Body); } finally { await messageSender.CloseAsync(); await messageReceiver.CloseAsync(); } }
async Task QueueClientShouldPassPluginsToMessageSession() { await ServiceBusScope.UsingQueueAsync(partitioned : false, sessionEnabled : true, async queueName => { var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName); try { var messageReceived = false; var sendReceivePlugin = new SendReceivePlugin(); queueClient.RegisterPlugin(sendReceivePlugin); var sendMessage = new Message(Encoding.UTF8.GetBytes("Test message")) { MessageId = Guid.NewGuid().ToString(), SessionId = Guid.NewGuid().ToString() }; await queueClient.SendAsync(sendMessage); // Ensure the plugin is called. Assert.True(sendReceivePlugin.MessageBodies.ContainsKey(sendMessage.MessageId)); queueClient.RegisterSessionHandler( (session, message, cancellationToken) => { Assert.Equal(sendMessage.SessionId, session.SessionId); Assert.True(session.RegisteredPlugins.Contains(sendReceivePlugin)); Assert.Equal(sendMessage.Body, message.Body); messageReceived = true; return(Task.CompletedTask); }, exceptionArgs => Task.CompletedTask); for (var i = 0; i < 20; i++) { if (messageReceived) { break; } await Task.Delay(TimeSpan.FromSeconds(2)); } Assert.True(messageReceived); } finally { await queueClient.CloseAsync(); } }); }