/// <summary> /// 创建订阅者 /// </summary> /// <param name="clientOption"></param> /// <returns></returns> public IConsumerClient Create(ClientOption clientOption) { try { _channelPoolCollection.TryGetValue(clientOption.Name, out IChannelPool pool); ConsumerClient client = new ConsumerClient(clientOption, pool, _rabbitMQOptions.Options.First(a => a.Name == clientOption.Name)); client.Connect(); return(client); } catch (System.Exception e) { throw new BrokerConnectionException(e); } }
private void GenerateChannel(Message message, ref IModel channel, ref IChannelPool pool, out IBasicProperties props, out string exchage, out string routingKey) { _channelPools.TryGetValue(message.GetName() ?? "", out pool); channel = pool.GetChannel(); props = channel.CreateBasicProperties(); props.DeliveryMode = 2; exchage = message.GetExchange() ?? throw new ArgumentNullException("the exchange is null."); routingKey = message.GetRoutingKey() ?? ""; if (message.IsInitQueue()) { // 声明一个交换机 string exchangeType = message.GetExchangeType() ?? throw new ArgumentNullException("the exchange type is null."); channel.ExchangeDeclare(exchage, exchangeType, true); // 声明一个队列 然后把队列和交换机绑定起来 string queue = message.GetQueueName(); channel.QueueDeclare(queue, true, false, false); channel.QueueBind(queue, exchage, routingKey); } message.Remove(); TransferHeaderProperties(props, message.Headers); }