0

Background

I'm using RabbitMQ with C#. I have a remote queue with one publisher and one consumer. This is how I enqueue a message into the queue (publisher):

model.BasicPublish(exchange, routingKey, basicProperties, body);

I just figured out that this call is always a success (success = no error reported, exceptions). For example, even if I not connected to the network (the queue is unreachable) - it still passes this line and I don't know about it.

The Question:

In a complex system, reliability is above all. So how I can be sure that the message is enqueued into the queue?

I think that must be a mechanism to:

  1. Retry message queue insertion in case of retry
  2. A reporting system that will give a report before the producer will drop the message (won't be tried again).

Possible solution

I saw here that I can implement something like transaction, which makes the call atomic and also reports in case of error. For me, it looks like "too big hammer". Transactions have large effect on performance.

No1Lives4Ever
  • 6,430
  • 19
  • 77
  • 140

1 Answers1

1

OK. Found the solution.

About possible solution #1:

Taken from RabbitMQ documentation (source):

Using standard AMQP 0-9-1, the only way to guarantee that a message isn't lost is by using transactions -- make the channel transactional then for each message or set of messages publish, commit. In this case, transactions are unnecessarily heavyweight and decrease throughput by a factor of 250. To remedy this, a confirmation mechanism was introduced. It mimics the consumer acknowledgements mechanism already present in the protocol.

According to this article, the right solution is to use "Publisher confirms". Based on this answer, all I have to do is:

channel.BasicPublish(QUEUE_NAME, QUEUE_NAME, messageProperties, payload);
channel.WaitForConfirmsOrDie();
No1Lives4Ever
  • 6,430
  • 19
  • 77
  • 140
  • 1
    `channel.WaitForConfirmsOrDie()` is synchronous and will severely limit performance. The technique described in [this tutorial](https://www.rabbitmq.com/tutorials/tutorial-seven-java.html) applies to the .NET client library as well - you should read it. – Luke Bakken Sep 09 '19 at 14:44
  • Interesting. Thanks for sharing. – No1Lives4Ever Sep 10 '19 at 06:01