gpt4 book ai didi

c# - Docker RabbitMQ 消息在重启时消失

转载 作者:行者123 更新时间:2023-12-05 04:55:14 25 4
gpt4 key购买 nike

我使用这个命令行新建 RabbitMQ 容器

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

代码设置durable:true,则重启容器队列存在,消息消失

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

enter image description here

请问什么问题?谢谢

最佳答案

来自 official documentation :

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

所以你需要这样的东西:

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

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

关于c# - Docker RabbitMQ 消息在重启时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65489763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com