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

发送成功

相关推荐
菜鸟康2 小时前
C++实现分布式网络通信框架RPC(2)——rpc发布端
分布式·网络协议·rpc
斯普信专业组4 小时前
Kafka主题运维全指南:从基础配置到故障处理
运维·分布式·kafka
百度Geek说4 小时前
BaikalDB 架构演进实录:打造融合向量化与 MPP 的 HTAP 查询引擎
数据库·分布式·架构
q567315236 小时前
分布式增量爬虫实现方案
开发语言·分布式·爬虫·python
一叶知秋哈8 小时前
Canal1.1.5监听Mysql数据变动发送消息给Rabbit MQ
mysql·rabbitmq
懒虫虫~11 小时前
基于SpringBoot利用死信队列解决RabbitMQ业务队列故障重试无效场景问题
spring boot·rabbitmq
Chan1616 小时前
【 SpringCloud | 微服务 MQ基础 】
java·spring·spring cloud·微服务·云原生·rabbitmq
小鸡脚来咯17 小时前
RabbitMQ入门
分布式·rabbitmq
qq_4639448618 小时前
【Spark征服之路-2.2-安装部署Spark(二)】
大数据·分布式·spark
敖云岚19 小时前
【Redis】分布式锁的介绍与演进之路
数据库·redis·分布式