public CustomRabbitConsumer(
     global::RabbitMQ.Client.IModel model,
     RabbitQueueDescription queueDescription)
     : base(model)
 {
     QueueDescription = queueDescription;
 }
Exemple #2
0
 private static void DeclareQueue(IModel channel, RabbitQueueDescription queueDescription)
 {
     channel.QueueDeclare(queueDescription);
     foreach (var queueBinding in queueDescription.Bindings)
     {
         if (queueBinding.RoutingKeys?.Any() == true)
         {
             foreach (var routingKey in queueBinding.RoutingKeys)
             {
                 channel.QueueBind(
                     queue: queueDescription.QueueName,
                     exchange: queueBinding.ExchangeName,
                     routingKey: routingKey,
                     arguments: queueBinding.AdditionnalProperties);
             }
         }
         else
         {
             channel.QueueBind(
                 queue: queueDescription.QueueName,
                 exchange: queueBinding.ExchangeName,
                 routingKey: "",
                 arguments: queueBinding.AdditionnalProperties);
         }
     }
 }
 public static void QueueDeclare(this IModel channel, RabbitQueueDescription queueDescription)
     => channel.QueueDeclare(
         queue: queueDescription.QueueName,
         durable: queueDescription.Durable,
         exclusive: queueDescription.Exclusive,
         autoDelete: queueDescription.AutoDelete,
         arguments: queueDescription.AdditionnalProperties);
Exemple #4
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");
            }
        }