3
我嘗試構建持續消息隊列,每個消息都有一些延遲。在Java代碼它看起來像這樣:RabbitMQ中的消息丟失
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare("WorkExchange", "direct");
channel.queueDeclare("WorkQueue", true, false, false, null);
channel.queueBind("WorkQueue", "WorkExchange", "");
Map<String, Object> args = new HashMap<>();
args.put("x-dead-letter-exchange", "WorkExchange");
channel.exchangeDeclare("RetryExchange", "direct");
channel.queueDeclare("RetryQueue", true, false, false, args);
channel.queueBind("RetryQueue", "RetryExchange", "");
channel.confirmSelect();
BasicProperties properties = new BasicProperties();
properties.setDeliveryMode(2);
properties.setExpiration("120000");
channel.basicPublish("RetryExchange", "", properties, "Hello world!".getBytes());
channel.waitForConfirmsOrDie();
connection.close();
但是,我有一些持久性的問題。當我停止服務器時,等待一段時間並重新啓動它,必須移動到WorkQueue的消息纔會消失。我做錯了什麼?或者它是由設計?