时间:2024-9-1 作者:老大夫 分类: RabbitMQ
别忘了设置绑定关系:
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
@Test
public void testSendMessageTTL() {
// 1、创建消息后置处理器对象
MessagePostProcessor messagePostProcessor = (Message message) -> {
// 设定 TTL 时间,以毫秒为单位
message.getMessageProperties().setExpiration("5000");
return message;
};
// 2、发送消息
rabbitTemplate.convertAndSend(
EXCHANGE_DIRECT,
ROUTING_KEY,
"Hello atguigu", messagePostProcessor);
}
这次我们是发送到普通队列上:
推荐阅读:
RabbitMQ交换机类型
Operation007-SpringBoot
Operation019-Federation
Operation006-Topics
Operation018-Stream
Operation004-PubSub
Operation001-Install
Operation008-Confirm01-A-Producer生产者端消息确认机制
Operation012-DelayPlugin
Operation020-Shovel
行动消除疑虑