1
votes

I'm trying to implement RabbitMQ Request-Response pattern.

My goal is that there would be always one consumer that listens to a queue and replies to messages.

So I've set the server up by:

var consumer = new EventingBasicConsumer(channel);

channel.BasicConsume(queue: 'listensToThisQueue',
   noAck: true,
   consumer: consumer);

consumer.Received += (model, ea) =>
{ 
   // Replying to client
   channel.BasicPublish(exchange: '',
            routingKey: routingKey,
            basicProperties: props,
            body: message);
   // Basic ack
   channel.BasicAck(deliveryTag: incomingDeliveryTag,
            multiple: false);
}

Everything actually works fine:

  1. Client sends first message
  2. Server receive and reply
  3. Client gets the message

The only problem is that after finshing Received method (After executing BasicAck) - Consumer stops listening to listenToQueue (I actually see 0 consumers on this queue in the UI management).

Why is that ?

1

1 Answers

0
votes

This is happening because you are subscribing to the queue with noAck set to True. In this case, the consumer crashed after the first message was delivered (which is why you see 0 consumers). So you have to subscribe to the queue with noAck set to False.