コード例 #1
0
        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.BasicConsume(
                    queue: Queue.QueueName,
                    autoAck: false,
                    consumer: consumer
                    );

                Channel = channel;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, LogLevel.Warning);
                AsyncHelper.RunSync(() => ExceptionNotifier.NotifyAsync(ex, logLevel: LogLevel.Warning));
            }
        }
コード例 #2
0
 protected virtual IModel CreateChannel(string channelName, string connectionName)
 {
     return(ConnectionPool
            .Get(connectionName)
            .CreateModel());
 }