コード例 #1
0
        public async Task AMessageIsForwardedToMoreQueuesWithMatchingTopicFilters()
        {
            var target = new MessageBroker();

            target.QueueDeclare("FirstQueue", new List <string>()
            {
                "My.*", "MVM.PolisService"
            });
            EventMessage receivedFromFirstQueue = null;

            target.BasicComsume("FirstQueue", m => { receivedFromFirstQueue = m; });

            target.QueueDeclare("SecondQueue", new List <string>()
            {
                "MVM.OtherService", "*.SomeTopic"
            });
            EventMessage receivedFromSecondQueue = null;

            target.BasicComsume("SecondQueue", m => { receivedFromSecondQueue = m; });

            var message = new EventMessage
            {
                Topic         = "My.SomeTopic",
                CorrelationId = Guid.NewGuid(), Timestamp = DateTime.Now.Ticks, EventType = "My.SomethingHappened", Body = Encoding.Unicode.GetBytes("{'Number':5}"),
            };

            await target.BasicPublishAsync(message);

            Assert.IsNotNull(receivedFromFirstQueue);
            Assert.AreEqual("My.SomeTopic", receivedFromFirstQueue.Topic);
            Assert.IsNotNull(receivedFromSecondQueue);
            Assert.AreEqual("My.SomeTopic", receivedFromSecondQueue.Topic);
        }
コード例 #2
0
        public async Task WhenAMessageIsPublished_ItIsLogged()
        {
            var target  = new MessageBroker();
            var message = new EventMessage
            {
                Topic         = "My.SomeTopic",
                CorrelationId = Guid.NewGuid(), Timestamp = DateTime.Now.Ticks, EventType = "My.SomethingHappened", Body = Encoding.Unicode.GetBytes("{'Number':5}"),
            };

            await target.BasicPublishAsync(message);

            Assert.AreEqual(1, target.LoggedMessages.Count());
            Assert.AreEqual("My.SomeTopic", target.LoggedMessages.First().Topic);
        }
コード例 #3
0
        public async Task AMessageIsForwardedToAQueueWithMatchingTopicFilter()
        {
            var target = new MessageBroker();

            target.QueueDeclare(queueName, topicFilters);
            EventMessage receivedMessage = null;

            target.BasicComsume(queueName, m => { receivedMessage = m; });

            var message = new EventMessage
            {
                Topic         = "My.SomeTopic",
                CorrelationId = Guid.NewGuid(), Timestamp = DateTime.Now.Ticks, EventType = "My.SomethingHappened", Body = Encoding.Unicode.GetBytes("{'Number':5}"),
            };
            await target.BasicPublishAsync(message);

            Assert.IsNotNull(receivedMessage);
            Assert.AreEqual("My.SomeTopic", receivedMessage.Topic);
        }