private void SetupExchangeAndQueue(IModel channel) { channel.ExchangeDeclare(this.queueConfig.Exchange, ExchangeType.Direct); var queueSetup = new QueueSetup(this.queueConfig); queueSetup.DeclareQueue(channel); channel.QueueBind( queue: this.queueConfig.QueueName, exchange: this.queueConfig.Exchange, routingKey: this.queueConfig.DefaultRoutingKey, arguments: null); }
public void StartListening() { this.logger.LogDebug("Initializing connection to {host}", this.queueConnectionFactory.HostName); using (var queueConn = this.queueConnectionFactory.CreateConnection()) using (var queueChannel = queueConn.CreateModel()) { this.logger.LogDebug( "Connected to {host}. Declaring queue {queue}", queueConn.Endpoint.HostName, this.queueConfig.QueueName); var queueSetup = new QueueSetup(this.queueConfig); queueSetup.DeclareQueue(queueChannel); var queueConsumer = new AsyncEventingBasicConsumer(queueChannel); queueConsumer.Received += async(sender, e) => { await ProcessMessage(queueChannel, e); }; this.logger.LogInformation( "Monitoring queue {queue} on {host}", this.queueConfig.QueueName, queueConn.Endpoint.HostName); queueChannel.BasicQos( prefetchCount: this.queueConfig.PrefetchCount, prefetchSize: 0, global: true); queueChannel.BasicConsume( queue: this.queueConfig.QueueName, autoAck: false, consumer: queueConsumer); Console.ReadLine(); } }