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

发送成功

相关推荐
AAA修煤气灶刘哥7 小时前
别让Redis「歪脖子」!一次搞定数据倾斜与请求倾斜的捉妖记
redis·分布式·后端
往事随风去18 小时前
架构师必备思维:从“任务队列”到“事件广播”,彻底吃透消息队列两大设计模式
消息队列·rabbitmq
Aomnitrix19 小时前
知识管理新范式——cpolar+Wiki.js打造企业级分布式知识库
开发语言·javascript·分布式
程序消消乐19 小时前
Kafka 入门指南:从 0 到 1 构建你的 Kafka 知识基础入门体系
分布式·kafka
智能化咨询19 小时前
Kafka架构:构建高吞吐量分布式消息系统的艺术——进阶优化与行业实践
分布式·架构·kafka
Chasing__Dreams19 小时前
kafka--基础知识点--5.2--最多一次、至少一次、精确一次
分布式·kafka
在未来等你1 天前
Elasticsearch面试精讲 Day 17:查询性能调优实践
大数据·分布式·elasticsearch·搜索引擎·面试
大数据CLUB1 天前
基于spark的澳洲光伏发电站选址预测
大数据·hadoop·分布式·数据分析·spark·数据开发
ajax_beijing1 天前
zookeeper是啥
分布式·zookeeper·云原生