在工作模式中,默认是平均分配,轮询需要增加配置
工作模式与一般模式代码相同,不再编写
广播模式:fanout类型,需要绑定交换机
@Test
public void testFanout() {
rabbitTemplate.convertAndSend("logs","","hello word");
}
@RabbitListener(bindings = {
@QueueBinding(
value = @Queue,
exchange = @Exchange(value = "logs",type = "fanout")
)
})
public void receive(String message){
System.out.println("message="+message);
}
路由模式:与广播模式只在注解时有区别
@RabbitListener(bindings = {
@QueueBinding(
value = @Queue,
exchange = @Exchange(value = "logs",type = "direct"),
key = {"info","erro","debug"}
)
})
public void receive(String message){
System.out.println("message="+message);
}
topic订阅模式:与路由模式区别在动态
@RabbitListener(bindings = {
@QueueBinding(
value = @Queue,
exchange = @Exchange(value = "logs",type = "direct"),
key = {"info。*"}
)
})
public void receive(String message){
System.out.println("message="+message);
}