public RabbitMQSubscribeMiddleware(
            IChannelPool channelPool,
            IRabbitMqSerializer serializer)
        {
            this.serializer  = serializer;
            this.channelPool = channelPool;

            ChannelAccessor = channelPool.Acquire(ChannelQueueName, ConnectionName);


            QueueDeclareConfiguration QueueConfiguration = new QueueDeclareConfiguration(ChannelQueueName);

            QueueConfiguration.Declare(ChannelAccessor.Channel);

            var properties = ChannelAccessor.Channel.CreateBasicProperties();

            properties.Persistent = true;



            Consumer           = new EventingBasicConsumer(ChannelAccessor.Channel);
            Consumer.Received += (model, ea) =>
            {
                var    body    = ea.Body.ToArray();
                string message = (string)serializer.Deserialize(ea.Body.ToArray(), typeof(string));
                Console.WriteLine(" [Subscribe] Received {0}", string.Format(message, DateTime.Now));
                ChannelAccessor.Channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
            };

            ChannelAccessor.Channel.BasicConsume(
                queue: QueueConfiguration.QueueName,
                autoAck: false,
                consumer: Consumer
                );
        }
예제 #2
0
 public RabbitMqDistributedEventBus(
     IConsumerFactory consumerFactory,
     IRabbitMqSerializer serializer,
     IEventBusSubscriptionsManager subscriptionsManager,
     IServiceProvider serviceProvider,
     IChannelPool channelPool,
     IOptions <EventBusOptions> eventBusOptions,
     IOptions <RabbitMqEventBusOptions> rabbitMOptions)
     : base(subscriptionsManager, serviceProvider, eventBusOptions)
 {
     RabbitMqOptions = rabbitMOptions.Value;
     ConsumerFactory = consumerFactory;
     Serializer      = serializer;
     ChannelPool     = channelPool;
     ChannelAccessor = ChannelPool.Acquire();
     Consumer        = ConsumerFactory.Create(
         new ExchangeDeclareConfiguration(
             RabbitMqOptions.Exchange,
             type: "direct",
             durable: true),
         new QueueDeclareConfiguration(
             RabbitMqOptions.QueueName,
             durable: true,
             exclusive: false,
             autoDelete: false),
         RabbitMqOptions.ConnectionName
         );
     Consumer.OnMessageReceived(ProcessEventAsync);
     _subsManager.OnEventRemoved += SubsManager_OnEventRemoved;
 }
 public RabbitMQPublishMiddleware(
     IChannelPool channelPool,
     IRabbitMqSerializer serializer)
 {
     this.serializer  = serializer;
     this.channelPool = channelPool;
     ChannelAccessor  = channelPool.Acquire(ChannelQueueName, ConnectionName);
 }
        private IChannelAccessor CreateChannelAndBindExchangeQueue()
        {
            var channelName     = $"sail.channels.{_exchange?.ExchangeName ?? "_"}.{_queue.QueueName}";
            var channelAccessor = _channels.Acquire(channelName, _connectionName);

            BindExchangeQueue(channelAccessor);
            return(channelAccessor);
        }
 public RabbitBasicDemo(
     IChannelPool channelPool,
     IRabbitMqSerializer serializer,
     ILogger <RabbitBasicDemo> logger)
 {
     _logger          = logger;
     this.serializer  = serializer;
     this.channelPool = channelPool;
     ChannelAccessor  = channelPool.Acquire(ChannelQueueName, ConnectionName);
 }