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.
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:
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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With