No1Lives4Ever
No1Lives4Ever

Reputation: 6883

RabbitMQ publish a message with REST API

I have an application written in Python (PIKA) and C# (official NuGet package). Those applications are publishing new messages into RabbitMQ queues.

Until now, I used this syntax to publish a new message into the queue:

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

I found that BasicPublish function always returns with success. I also read in RabbitMQ documentation that in case of broker destroyed, the messages that didn't send yet will be removed without sending it to RabbitMQ.

I want to avoid the loss of messages. So, I found 3 options to submit those messages to publish:

  1. Transaction - Very slow.
  2. Confirmation - I found it tricky to implement in a multi-threaded environment.
  3. with REST API - What do you think about that?

I think that it will be ideal for me yo use REST API for inserting messages into queues.

The Question:

The way that I found to send a message with API is to send POST message to this endpoint:

http://localhost:15672/api/exchanges/vhost/amq.default/publish

As you can see, this port (15672) belongs to the RabbitMQ management system.

  1. Is this the right way to use RabbitMQ with REST API?
  2. Can I trust the RabbitMQ management system in the production environment?
  3. Can you recommend an alternative to REST API that will accept to message enqueue immediately after insertion (blocking)?

Upvotes: 1

Views: 6900

Answers (1)

Luke Bakken
Luke Bakken

Reputation: 9637

No, don't use the HTTP API. It is not intended for production use for publishing or consuming messages.

You must use publisher confirms. The technique described in this tutorial applies to the .NET client library as well.

You could also investigate libraries written on top of the official .NET library that may correctly implement publisher confirms for you. EasyNetQ is one such library.

Another good resource to read with concern to 100% reliability is this blog post.

Upvotes: 1

Related Questions