public MQChannel CreatePublishChannel(string exchange) { IModel model = this.MQConn.CreateModel(); model.ExchangeDeclare(exchange, ExchangeType.Topic, false, false, null); MQChannel channel = new MQChannel(ExchangeType.Topic, exchange, null, null) { Connection = this.MQConn, Channel = model }; return(channel); }
/// <summary> /// 创建消息通道 /// </summary> /// <param name="cfg"></param> 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, Consumer = consumer }; consumer.Received += channel.Receive; channel.Channel = model; return(channel); }
void initChannel() { MQChannelManager chManager = new MQChannelManager(this.Connection); if (this.ServiceConfig.QueueConfig.Consumers != null && this.ServiceConfig.QueueConfig.Consumers.Count > 0) { foreach (MQQueue item in this.ServiceConfig.QueueConfig.Consumers) { MQChannel mCh = chManager.CreateReceiveChannel(ExchangeType.Topic, item.ExchangeName, item.Queue, item.RouteKey); dicChannel[item.Key] = mCh; mCh.OnReceivedCallback = MQHandlerFactory.Create(item.HandlerType); //设置处理类 } } if (this.ServiceConfig.QueueConfig.Producers != null && this.ServiceConfig.QueueConfig.Producers.Count > 0) { foreach (MQExchage item in this.ServiceConfig.QueueConfig.Producers) { MQChannel mCh = chManager.CreatePublishChannel(item.ExchangeName); dicChannel[item.Key] = mCh; //mCh.OnReceivedCallback = MQHandlerFactory.Create(item.HandlerType); //设置处理类 } } }