RabbitMq——direct交换器和fanout交换器 扇形交换器

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

发送成功

相关推荐
Wang's Blog4 小时前
Elastic Stack梳理:Logstash Input插件详解与Codec插件应用指南之文件监控、多行日志处理与Kafka集成
分布式·搜索引擎·kafka·elastic search
int WINGsssss5 小时前
【无标题】
pytorch·分布式·python
小安同学iter6 小时前
天机学堂day05
java·开发语言·spring boot·分布式·后端·spring cloud·微服务
孟意昶6 小时前
Doris专题27-mysql兼容性与join连接
大数据·数据库·分布式·sql·mysql·doris
Wang's Blog6 小时前
Elastic Stack梳理:Logstash线程模型与多实例部署解析
分布式·elastic search
西岭千秋雪_7 小时前
MySQL日志梳理(存储引擎层)
java·数据库·分布式·mysql·oracle
小白|7 小时前
OpenHarmony + Flutter 混合开发进阶:构建支持离线优先、边缘同步与冲突解决的分布式数据应用
分布式·flutter
张人玉8 小时前
大数据hadoop系列——在ubuntu上安装HBase 伪分布式
大数据·hadoop·分布式·hbase
闲人编程9 小时前
API限流、鉴权与监控
分布式·python·wpf·限流·集群·令牌·codecapsule
苦学编程的谢9 小时前
RabbitMQ_4_高级特性(1)
分布式·rabbitmq