예제 #1
0
        public MQChannel CreateChannel(string queue, string routeKey, string exchangeType)
        {
            MQConnection     conn    = new MQConnection(this.Config, this.vHost);
            MQChannelManager cm      = new MQChannelManager(conn);
            MQChannel        channel = cm.CreateReceiveChannel(exchangeType, this.Exchange, queue, routeKey);

            return(channel);
        }
예제 #2
0
        /// <summary>
        /// 创建消息通道
        /// </summary>
        /// <param name="exchangeType"></param>
        /// <param name="exchange"></param>
        /// <param name="queue"></param>
        /// <param name="routekey"></param>
        /// <returns></returns>
        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.CreateConsumer(model, queue);
            MQChannel             channel  = new MQChannel(exchangeType, exchange, queue, routekey)
            {
                Connection = this.MQConn.Connection,
                Consumer   = consumer
            };

            consumer.Received += channel.Receive;
            return(channel);
        }
예제 #3
0
        /// <summary>
        ///  启动订阅
        /// </summary>
        public void Start()
        {
            if (started)
            {
                return;
            }
            MQConnection     conn    = new MQConnection(this.Config, this.vHost);
            MQChannelManager manager = new MQChannelManager(conn);

            foreach (var item in this.Queue)
            {
                MQChannel channel = manager.CreateReceiveChannel(item.ExchangeType, this.Exchange, item.Queue, item.RouterKey);
                channel.OnReceivedCallBack = item.OnReceived;
                this.Channels.Add(channel);
            }
            started = true;
        }