Handles all the logic to Send messages to an IOutboundTransport, based on current subscriptions Essentially takes Messages, transforms into TransportMessages, setting the appropriate headers for each subscription and sends them to an IOutboundTransport
Inheritance: IMessageBus
示例#1
0
        public void WhenMultipleSubscribers_EachGetOwnMessage()
        {
            // arrange
            var client = CreateOutboundTransportMock();

            // create two subscriptions for "mytopic"
            this.subscriptionStore.AddSubscription(new Subscription("mytopic", "e1", "c1"));
            this.subscriptionStore.AddSubscription(new Subscription("mytopic", "e2", "c2"));

            var bus = new MessageBus(this.subscriptionManager, client.Object, NullLoggerFactory.Instance);
            var message = new Message(new object(), "mytopic");

            // act
            bus.Send(message);

            // assert
            // since multiple messages are to be sent, it should use the SendMultiple method
            client.Verify(b => b.Send(It.IsAny<TransportMessage>()), Times.Never);
            client.Verify(b =>
                b.SendMultiple(It.Is<IEnumerable<TransportMessage>>(msgs =>
                    msgs.Count() == 2 &&
                    msgs.Count(m => m.Headers[MessageHeaders.Endpoint] == "e1" &&
                                    m.Headers[MessageHeaders.Component] == "c1") == 1 &&
                    msgs.Count(m => m.Headers[MessageHeaders.Endpoint] == "e2" &&
                                    m.Headers[MessageHeaders.Component] == "c2") == 1)
                    ), Times.Once);
        }
示例#2
0
        public void WhenNoSubscribers_MessageIsNotSent()
        {
            // arrange
            var client = CreateOutboundTransportMock();
            var bus = new MessageBus(this.subscriptionManager, client.Object, NullLoggerFactory.Instance);
            var message = new Message(new object(), "topic");

            // act
            bus.Send(message);

            // assert
            client.Verify(b => b.Send(It.IsAny<TransportMessage>()), Times.Never);
        }