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

发送成功

相关推荐
让我上个超影吧7 小时前
消息队列——RabbitMQ(高级)
java·rabbitmq
塔中妖9 小时前
Windows 安装 RabbitMQ 详细教程(含 Erlang 环境配置)
windows·rabbitmq·erlang
断手当码农10 小时前
Redis 实现分布式锁的三种方式
数据库·redis·分布式
初次攀爬者11 小时前
Redis分布式锁实现的三种方式-基于setnx,lua脚本和Redisson
redis·分布式·后端
业精于勤_荒于稀11 小时前
物流订单系统99.99%可用性全链路容灾体系落地操作手册
分布式
Ronin30512 小时前
信道管理模块和异步线程模块
开发语言·c++·rabbitmq·异步线程·信道管理
Asher050912 小时前
Hadoop核心技术与实战指南
大数据·hadoop·分布式
凉凉的知识库12 小时前
Go中的零值与空值,你搞懂了么?
分布式·面试·go
?Anita Zhang13 小时前
联邦学习实战:如何在分布式场景下构建隐私保护机器学习模型
人工智能·分布式·机器学习
tony36513 小时前
pytorch分布式训练解释
人工智能·pytorch·分布式