protected virtual void TryCreateChannel() { DisposeChannel(); try { var channel = ConnectionPool .Get(ConnectionName) .CreateModel(); channel.ExchangeDeclare( exchange: Exchange.ExchangeName, type: Exchange.Type, durable: Exchange.Durable, autoDelete: Exchange.AutoDelete, arguments: Exchange.Arguments ); channel.QueueDeclare( queue: Queue.QueueName, durable: Queue.Durable, exclusive: Queue.Exclusive, autoDelete: Queue.AutoDelete, arguments: Queue.Arguments ); var consumer = new EventingBasicConsumer(channel); consumer.Received += async(model, basicDeliverEventArgs) => { await HandleIncomingMessage(channel, basicDeliverEventArgs); }; channel.BasicQos(ConsumerConfiguration.PrefetchSize, ConsumerConfiguration.PrefetchCount, ConsumerConfiguration.Global); channel.BasicConsume( queue: Queue.QueueName, autoAck: false, consumer: consumer ); Channel = channel; } catch (Exception ex) { Logger.Warn(ex.Message, ex); } }
protected virtual IModel CreateChannel(string channelName, string connectionName) { return(ConnectionPool .Get(connectionName) .CreateModel()); }