0

I've searched StackOverflow and I don't think the other issues around multiple consumers match what I am trying.

I have a Windows service that starts and registers to monitor two different RabbitMQ queues. If I only register it to listen to 1 queue, it works fine. When I try to get it to listen to both queues, only the 2nd listener works.

var responseConsumer = new EventingBasicConsumer(_responseChannel);

responseConsumer.Received += (model, ea) =>
{
    var message = Encoding.UTF8.GetString(ea.Body);
    // PROCESS MESSAGE
    IssuerProcessor processor = new IssuerProcessor("Processed Message(" + pause + "ms) : ");

    Thread.Sleep(pause);

    var ret = processor.ProcessResponseMessage();
    Console.WriteLine("Processed message: " + ret);
    ulong deliveryTag = ea.DeliveryTag;

    _responseChannel.BasicAck(deliveryTag, false);
    Console.WriteLine("ACK RESPONSE Delivery Tag (" + deliveryTag.ToString() + "): " + ret);
}; // end requestConsumer.Received

_responseChannel.BasicConsume(queue: RESPONSE_QUEUE, autoAck: autoAck, consumer: responseConsumer);

The other consumer looks just like this one, but it listens to a different queue, using the same connection, with a different channel.

Here is the initialization for both:

_requestChannel = _connection.CreateModel();
_responseChannel = _connection.CreateModel();

_requestChannel.ExchangeDeclare(EXCHANGE, ExchangeType.Direct, true, false, null);
_requestChannel.QueueDeclare(queue: REQUEST_QUEUE, durable: true, exclusive: false, autoDelete: false, arguments: null);
_requestChannel.BasicQos(0, 1, false);
_requestChannel.QueueBind(REQUEST_QUEUE, EXCHANGE, REQUEST_QUEUE, null);

_responseChannel.ExchangeDeclare(EXCHANGE, ExchangeType.Direct, true, false, null);
_responseChannel.QueueDeclare(RESPONSE_QUEUE, durable: true, exclusive: false, autoDelete: false, arguments: null);
_responseChannel.BasicQos(0, 1, false);
_responseChannel.QueueBind(RESPONSE_QUEUE, EXCHANGE, RESPONSE_QUEUE, null);

1 Answer 1

0

The problem ended up being that the service was running on a single thread and it could not monitor both queues at the same time.

I just created two different Threads and started each consumer on a different Thread.

public void StartWorkerThreads()
{
    Thread receivingConsumerThread = new Thread(StartListenReceivingQueue);
    receivingConsumerThread.Start();

    Thread respondingConsumerThread = new Thread(StartListenRespondingQueue);
    respondingConsumerThread.Start();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.