超时死信消息:超时的消息
有两种超时消息:
消息所在的队列设置了超时时间
消息本身设置了超时时间
消息所在的队列设置了超时时间:所有在此队列的消息超过了设定时间都会成为死信
设置队列超时时间:
@Beanpublic Queue ttlQueue(){return QueueBuilder.durable("ttl.queue") // 指定队列名称,并持久化.ttl(10000) // 设置队列的超时时间,10秒.deadLetterExchange("dl.ttl.exchange") // 指定死信交换机.build();}
消息本身设置超时时间:
@Testpublic void testSendTTLMessage() throws InterruptedException {// 1.消息体// String msg = "超时消息...";Message msg = MessageBuilder.withBody("hello, ttl message".getBytes(StandardCharsets.UTF_8)).setExpiration("5000").build();// 2.发送消息rabbitTemplate.convertAndSend("ttl.direct","ttl", msg);log.info("发送消息成功...");}}
