Exemplo n.º 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();
            }
        }
Exemplo n.º 2
0
 public RabbitPublisher(
     ILoggerFactory loggerFactory,
     RabbitPublisherConfiguration configuration)
 {
     if (loggerFactory == null)
     {
         loggerFactory = new LoggerFactory();
         loggerFactory.AddProvider(new DebugLoggerProvider());
     }
     logger             = loggerFactory.CreateLogger <RabbitPublisher>();
     this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     RabbitCommonTools.DeclareExchangesAndQueueForPublisher(GetChannel(GetConnection()), configuration);
 }