Sobes.tech
Junior — Middle

Can you explain what the durable attribute means in RabbitMQ exchange settings?

sobes.tech AI

Answer from AI

The durable attribute in RabbitMQ exchange settings determines whether the exchange will be saved to disk and restored after the RabbitMQ server restarts. If durable is set to true, the exchange is considered durable and will not disappear upon broker restart. If false, the exchange will be temporary and will be deleted upon restart.

Example of creating a durable exchange in C# using the RabbitMQ.Client library:

var factory = new ConnectionFactory() { HostName = "localhost" };
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();

channel.ExchangeDeclare(exchange: "my_exchange", type: ExchangeType.Direct, durable: true);

Thus, a durable exchange guarantees the preservation of the exchange configuration between RabbitMQ restarts, which is important for the stable operation of the messaging system.