public async Task when_forwarding_a_message_with_a_custom_header_it_is_copied_to_the_message()
        {
            var forwarder        = new QueueMessageForwarder(queueClient, m => m.Properties["Test"] = "Value");
            var messageToForward = await MessageFactory.CreateMessageWithJsonBody();

            queueClient.Send(messageToForward);

            var receivedMessages = await queueClient.ReceiveBatchAsync(100, TimeSpan.FromSeconds(3));

            returnedLockTokens = await forwarder.ForwardMessages(receivedMessages);

            forwardedMessages = await queueClient.ReceiveBatchAsync(100, TimeSpan.FromSeconds(3));

            Assert.That(forwardedMessages.First().Properties.ContainsKey("Test"), Is.True);
            Assert.That(forwardedMessages.First().Properties["Test"], Is.EqualTo("Value"));
        }
Example #2
0
        public ServiceBusMessageForwarder(ILogger activityLogger, ILogger messageLogger, string sourceConnectionString, string destinationConnectionString,
                                          string ignoreQueues, string ignoreTopics, string ignoreSubscriptions, int messagesToHandle = 10)
        {
            _activityLogger = activityLogger;
            _messageLogger  = messageLogger;

            _subscriptionMessageForwarder = new SubscriptionMessageForwarder(_activityLogger, _messageLogger, messagesToHandle);
            _queueMessageForwarder        = new QueueMessageForwarder(_activityLogger, _messageLogger, messagesToHandle);

            _sourceConnectionString      = sourceConnectionString;
            _destinationConnectionString = destinationConnectionString;

            _sourceNamespaceManager      = NamespaceManager.CreateFromConnectionString(_sourceConnectionString);
            _destinationNamespaceManager = NamespaceManager.CreateFromConnectionString(_destinationConnectionString);

            _ignoreQueuesPatterns        = ignoreQueues.Split(',').Where(_ => !string.IsNullOrWhiteSpace(_)).ToArray();
            _ignoreTopicPatterns         = ignoreTopics.Split(',').Where(_ => !string.IsNullOrWhiteSpace(_)).ToArray();
            _ignoreSubscriptionsPatterns = ignoreSubscriptions.Split(',').Where(_ => !string.IsNullOrWhiteSpace(_)).ToArray();
        }
        public async Task when_forwarding_multiple_messages_all_lock_tokens_are_returned_and_the_messages_are_forwarded()
        {
            var forwarder         = new QueueMessageForwarder(queueClient, null);
            var messagesToForward = new List <BrokeredMessage>();

            messagesToForward.Add(await MessageFactory.CreateMessageWithJsonBody());
            messagesToForward.Add(await MessageFactory.CreateMessageWithJsonBody());
            await queueClient.SendBatchAsync(messagesToForward);

            var receivedMessages = await queueClient.ReceiveBatchAsync(100);

            returnedLockTokens = await forwarder.ForwardMessages(receivedMessages);

            forwardedMessages = await queueClient.ReceiveBatchAsync(100);

            Assert.That(returnedLockTokens.Count(), Is.EqualTo(2));
            CollectionAssert.AllItemsAreUnique(returnedLockTokens);
            Assert.That(forwardedMessages.Count(), Is.EqualTo(2));
        }
        public async Task when_forwarding_a_message_standard_headers_are_copied()
        {
            var messageId   = Guid.NewGuid().ToString();
            var contentType = "application/json";

            var forwarder        = new QueueMessageForwarder(queueClient, m => m.Properties["Test"] = "Value");
            var messageToForward = await MessageFactory.CreateMessageWithJsonBody();

            messageToForward.MessageId   = messageId;
            messageToForward.ContentType = contentType;

            queueClient.Send(messageToForward);

            var receivedMessages = await queueClient.ReceiveBatchAsync(100, TimeSpan.FromSeconds(3));

            returnedLockTokens = await forwarder.ForwardMessages(receivedMessages);

            forwardedMessages = await queueClient.ReceiveBatchAsync(100, TimeSpan.FromSeconds(3));

            Assert.That(forwardedMessages.First().MessageId, Is.EqualTo(messageId));
            Assert.That(forwardedMessages.First().ContentType, Is.EqualTo(contentType));
        }