public void Subscribe()
        {
            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));
                _logger.LogInformation(" [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
                );
        }
        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
                );
        }
        public void Publish(string message)
        {
            QueueDeclareConfiguration QueueConfiguration = new QueueDeclareConfiguration(ChannelQueueName);

            QueueConfiguration.Declare(ChannelAccessor.Channel);

            var properties = ChannelAccessor.Channel.CreateBasicProperties();

            properties.Persistent = true;

            ChannelAccessor.Channel.BasicPublish(
                exchange: "",
                routingKey: QueueConfiguration.QueueName,
                basicProperties: properties,
                body: serializer.Serialize(string.Format(message, DateTime.Now))
                );
            _logger.LogInformation(" [RabbitBasicDemo] Publish {0}", string.Format(message, DateTime.Now));
        }
        public Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            QueueDeclareConfiguration QueueConfiguration = new QueueDeclareConfiguration(ChannelQueueName);

            QueueConfiguration.Declare(ChannelAccessor.Channel);

            var properties = ChannelAccessor.Channel.CreateBasicProperties();

            properties.Persistent = true;

            ChannelAccessor.Channel.BasicPublish(
                exchange: "",
                routingKey: QueueConfiguration.QueueName,
                basicProperties: properties,
                body: serializer.Serialize(string.Format(message, DateTime.Now))
                );
            Console.WriteLine(" [Publish] Publish {0}", string.Format(message, DateTime.Now));
            return(next.Invoke(context));
        }