示例#1
0
        public MQChannel CreateChannel(string queue, string routeKey, string exchangeType)
        {
            MQConnection conn    = new MQConnection(this.UserName, this.Password, this.Host, this.Port, this.vHost, this.logger);
            MQChannel    channel = conn.CreateReceiveChannel(exchangeType, this.Exchange, queue, routeKey);

            return(channel);
        }
示例#2
0
        public MQChannel CreateReceiveChannel(string exchangeType, string exchange, string queue, string routekey)
        {
            IModel model = this.CreateModel(exchangeType, exchange, queue, routekey);

            model.BasicQos(0, 1, false);
            EventingBasicConsumer consumer = this.Receive(model, queue);

            consumer.Registered        += (object sender, ConsumerEventArgs e) => { _logger?.LogDebug($"已注册消费队列,{e.ConsumerTag}"); };
            consumer.Shutdown          += (object sender, ShutdownEventArgs e) => { _logger?.LogDebug($"已关闭消费队列,{e.ReplyCode},{e.ReplyText}"); };
            consumer.ConsumerCancelled += (object sender, ConsumerEventArgs e) => { _logger?.LogDebug($"已退出消费队列,{e.ConsumerTag}"); };

            MQChannel channel = new MQChannel()
            {
                Connection       = this.connection,
                Consumer         = consumer,
                ExchangeName     = exchange,
                ExchangeTypeName = exchangeType,
                QueueName        = queue,
                RoutekeyName     = routekey
            };

            consumer.Received += channel.Receive;

            return(channel);
        }