RabbitMQ 发送消息到交换机

发布时间 2023-12-02 19:37:44作者: 嘎嘎鸭2

发送消息到交换机的代码:

@GetMapping("/mq02")//发送消息给交换机
public void mq02(){
String exchangeName = "hmall.fanout";
String msg = "hello, 每个人";
//三个参数:交换机名称、RoutingKey(暂时为空)、要发送的消息
rabbitTemplate.convertAndSend(exchangeName, null, msg);
}

回顾:发送消息到队列的代码:

@GetMapping("/mq01")//发送消息给队列
public void mq01(){
String queueName = "simple.queue";
String msg = "你好态爷";
rabbitTemplate.convertAndSend(queueName, msg);//队列名称、要发送的消息
}