direct交换器:
@Configuration
=发送=
@Bean
protected Queue queue(){
Queue queue = new Queue("myQueue")
return queue;
}
amqpTemplate.convertAndSend("myQueue","这是发送的内容"); 发送RabbitMq
发送成功
=接收=消费者(新项目)
@Conponent
@RabbitListener(queues="myQueue")注解某个方法为接收消息方法
public void Demo(String message){
}
@Conponent
(queues="myQueue")注解某个方法为接收消息方法
public void Demo2(String message){
}
fanout交换器 扇形交换器:
@Configuration
=发送=
@Bean
protected Queue createQueue1(){
Queue queue = new Queue("myfanout1")
return queue;
}
@Bean
protected Queue createQueue2(){
Queue queue = new Queue("myfanout2")
return queue;
}
创建交换器:
@Bean
public FanoutExchange getFanoutExchange()
{ return new FanoutExchange ("amq.fanout")
}
创建的交换器和消息队列绑定
@bean
public Binding binding(Queue createQueue1,FanoutExchange getFanoutExchange){
return BindingBuilder.bind(createQueue1).to(getFanoutExchange);
}
@bean
public Binding binding2(Queue createQueue2,FanoutExchange getFanoutExchange){
return BindingBuilder.bind(createQueue2).to(getFanoutExchange);
}
测试
amqpTemplate.convertAndSend("amq.fanout","core","fanout message"); 发送RabbitMq
发送成功