Senior
RabbitMQ — have you worked with it, tell about its features?
sobes.tech AI
Answer from AI
RabbitMQ is a message broker implementing the AMQP protocol. Main features:
- Reliability: support for delivery confirmations (ack), persistent queues, and messages.
- Flexible routing: exchanges of different types (direct, topic, fanout, headers) allow flexible message routing.
- Support for various messaging models: queues, pub/sub, RPC.
- Clustering and high availability: clusters can be created for scaling and high availability.
- Plugins and extensibility: support for plugins for monitoring, management, and integrations.
Example of usage in C# with the RabbitMQ.Client library:
var factory = new ConnectionFactory() { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
channel.QueueDeclare(queue: "task_queue", durable: true, exclusive: false, autoDelete: false, arguments: null);
string message = "Hello RabbitMQ!";
var body = Encoding.UTF8.GetBytes(message);
var properties = channel.CreateBasicProperties();
properties.Persistent = true; // ensure message persistence across broker restarts
channel.BasicPublish(exchange: "", routingKey: "task_queue", basicProperties: properties, body: body);
Console.WriteLine(" [x] Sent {0}", message);
RabbitMQ is well-suited for building distributed systems with asynchronous task processing and microservices integration.