发送消息到交换机的代码:
@GetMapping("/mq02")//发送消息给交换机
public void mq02(){
String exchangeName = "hmall.fanout";
String msg = "hello, 每个人";
//三个参数:交换机名称、RoutingKey(暂时为空)、要发送的消息
rabbitTemplate.convertAndSend(exchangeName, null, msg);
}
回顾:发送消息到队列的代码:
@GetMapping("/mq01")//发送消息给队列标签:String,队列,RabbitMQ,发送,交换机,消息,msg From: https://www.cnblogs.com/gagaya2/p/17872109.html
public void mq01(){
String queueName = "simple.queue";
String msg = "你好态爷";
rabbitTemplate.convertAndSend(queueName, msg);//队列名称、要发送的消息
}