Docker RabbitMQ Message disappear on restart

Viewed 1001

I use this command line new RabbitMQ container

docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq --hostname rabbitmq rabbitmq:management

Code setting durable:true, then restart container queue is exists, message is disappeared

channel.QueueDeclare(
    queue: name,        
    durable: true,      
    exclusive: false,   
    autoDelete: false,  
    arguments: null     
);

enter image description here

Please ask what question? thanks

2 Answers

From official documentation:

When RabbitMQ quits or crashes it will forget the queues and messages unless you tell it not to. Two things are required to make sure that messages aren't lost: we need to mark both the queue and messages as durable.

So you need something like this:

var properties = channel.CreateBasicProperties();
properties.Persistent = true;

channel.BasicPublish(exchange: "",
                     routingKey: "task_queue",
                     basicProperties: properties,
                     body: body);
Related