Beispiel #1
0
        public async Task PublishAsync_Should_Sent_To_Service_Exchange()
        {
            try
            {
                var networkInfos = RabbitNetworkInfos.GetConfigurationFor("CQELight", RabbitMQExchangeStrategy.Custom);
                networkInfos.ServiceExchangeDescriptions.Add(new RabbitExchangeDescription("pub1_exchange"));
                var config = new RabbitPublisherConfiguration
                {
                    ConnectionInfos = GetConnectionInfos(),
                    NetworkInfos    = networkInfos
                };
                RabbitCommonTools.DeclareExchangesAndQueueForPublisher(channel, config);
                channel.QueueDeclare("CQELight");
                channel.QueueBind("CQELight", "pub1_exchange", "");

                var publisher = new RabbitPublisher(
                    loggerFactory,
                    config);

                await publisher.PublishEventAsync(new TestEvent());

                var result = channel.BasicGet("CQELight", true);
                result.Should().NotBeNull();
                Encoding.UTF8.GetString(result.Body.ToArray()).FromJson <TestCommand>().Should().NotBeNull();
            }
            finally
            {
                DeleteData();
            }
        }
Beispiel #2
0
        public async Task PublishAsync_RoutingKey_Topic_Should_BeConsidered()
        {
            try
            {
                var fakeRoutingKeyFactory = new Mock <IRoutingKeyFactory>();
                fakeRoutingKeyFactory
                .Setup(m => m.GetRoutingKeyForEvent(It.IsAny <object>()))
                .Returns("cqelight.events.testevent");

                var networkInfos = RabbitNetworkInfos.GetConfigurationFor("CQELight", RabbitMQExchangeStrategy.Custom);
                networkInfos.ServiceQueueDescriptions.Add(new RabbitQueueDescription("CQELight"));
                networkInfos.ServiceExchangeDescriptions.Add(new RabbitExchangeDescription("MyCustomExchange")
                {
                    ExchangeType = ExchangeType.Topic
                });
                var queue = new RabbitQueueDescription("MyCustomQueue");
                queue.Bindings.Add(new RabbitQueueBindingDescription("MyCustomExchange")
                {
                    RoutingKeys = new List <string> {
                        "*.events.*"
                    }
                });
                networkInfos.ServiceQueueDescriptions.Add(queue);
                var config = new RabbitPublisherConfiguration
                {
                    ConnectionInfos   = GetConnectionInfos(),
                    NetworkInfos      = networkInfos,
                    RoutingKeyFactory = fakeRoutingKeyFactory.Object
                };
                var publisher = new RabbitPublisher(
                    loggerFactory,
                    config);

                await publisher.PublishEventAsync(new TestEvent());

                channel.BasicGet("CQELight", true).Should().BeNull();

                var result = channel.BasicGet("MyCustomQueue", true);
                result.Should().NotBeNull();
                Encoding.UTF8.GetString(result.Body.ToArray()).FromJson <TestEvent>().Should().NotBeNull();
            }
            finally
            {
                DeleteData();
                channel.QueueDelete("MyCustomQueue");
                channel.ExchangeDelete("MyCustomExchange");
            }
        }