- 设置队列的过期时间:
Map<String,Object> map = new HashMap<>(); map.put("x-message-ttl",2000); channel.queueDeclare(queueName,true,false,false,map); channel.queueBind(queueName,exchangeName,"router.key"); channel.basicPublish(exchangeName,"message",null,"message".getBytes());
- 发送消息设置过期时间:
MessageProperties messageProperties = new MessageProperties(); messageProperties.setExpiration("600000"); byte[] msgBytes = rabbitJson1.toJSONString().getBytes(); Message message = new Message(msgBytes, messageProperties); rabbitUtil.convertAndSend(mqConfig.getExBc(), "routtingkey", message);
3.设置队列过期时间:
Map<String, Object> map = new HashMap<>(); map.put("x-expires", 600000); channel.queueDeclare(queueName, true, false, false, map); channel.queueBind(queueName,exchangeName,"routtingkey");
RabbitMQ设置消息过期时间:
最新推荐文章于 2024-03-25 09:30:45 发布