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 小时前
RabbitMQ 如何保证消息不丢失和不重复消费?掌握这 4 个关键点就够了
java·后端·rabbitmq
码以致用3 小时前
Kafka笔记
笔记·分布式·kafka
回家路上绕了弯5 小时前
Vavr 工具实用指南:Java 函数式编程的高效落地方案
分布式·后端
BullSmall7 小时前
Kafka单机与集群部署全攻略
分布式·kafka
隐语SecretFlow8 小时前
如何在 Kuscia 上运行 SCQL 联合分析任务
分布式·安全·架构·开源
少许极端8 小时前
Redis入门指南:从零到分布式缓存-hash与list类型
redis·分布式·缓存·list·hash
jiayong2310 小时前
RabbitMQ 完全指南
分布式·rabbitmq
luod10 小时前
RabbitMQ工作队列模式理解
rabbitmq
BullSmall11 小时前
JDK17下Kafka部署全指南
分布式·kafka
悟空码字11 小时前
SpringBoot 整合 RabbitMQ:和这只“兔子”交朋友
java·后端·rabbitmq