1.设置RouteKey
注意交换机要改为
2.代码
@Test
public void sendtest3(){
rabbitTemplate.convertAndSend("exchanges1","1","路由模式");
}
@Test
public void sendtest4(){
rabbitTemplate.convertAndSend("exchanges1","2","路由模式");
}
消费者1
@Component
@RabbitListener(queues = "queues1")
public class RabbitConsumer1 {
@RabbitHandler
public void listen1(String message){
System.out.println("第一个消费者");
System.out.println(message);
}
}
消费者2
@Component
@RabbitListener(queues = "queues2")
public class RabbitConsumer2 {
@RabbitHandler
public void listen1(String message){
System.out.println("第二个消费者");
System.out.println(message);
}
}