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 小时前
大表优化实战指南:从千万到亿级数据的性能蜕变
分布式·后端
CrazyClaz3 小时前
分布式事务专题5
分布式·分布式事务
灯下夜无眠4 小时前
spark集群文件分发问题
大数据·分布式·spark
少许极端5 小时前
Redis入门指南:从零到分布式缓存-string类型
redis·分布式·缓存
Macbethad6 小时前
WPF工业设备诊断管理程序技术方案
大数据·hadoop·分布式
Thomas21437 小时前
pyspark3.5给paimon1.2的表打tag报错 spark_catalog is not a ProcedureCatalog
大数据·分布式·spark
稚辉君.MCA_P8_Java7 小时前
Gemini永久会员 Hadoop分布式计算框架MapReduce
大数据·hadoop·分布式·架构·mapreduce
CrazyClaz7 小时前
分布式事务专题4
分布式·分布式事务
程序员小胖8 小时前
每天一道面试题之架构篇|异步确保型事务——消息队列驱动的分布式事务解决方案
分布式·面试
CrazyClaz8 小时前
分布式事务专题2
分布式·分布式事务