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

发送成功

相关推荐
大猫子的技术日记24 分钟前
[后端杂货铺]深入理解分布式事务与锁:从隔离级别到传播行为
分布式·后端·事务
CRUD酱3 小时前
RabbitMQ是如何确保消息的可靠性的?
java·python·rabbitmq
小股虫3 小时前
分布式一致性算法深度解析:Paxos、Raft与ZAB的原理、实现与应用
分布式
Tan_Ying_Y4 小时前
分布式环境下,怎么保证线程安全
分布式
seven_7678230984 小时前
【前瞻创想】Kurator架构演进与云原生未来
分布式·云原生·架构·kurator·全链路
luod4 小时前
RabbitMQ简单生产者和消费者实现
java·rabbitmq
@鱼香肉丝没有鱼5 小时前
大模型分布式微调 & Xtuner
分布式·大模型微调·xtuner·llamafactory
Wokoo75 小时前
C/S 架构与 B/S 架构:核心差异 + 选型指南
分布式·后端·中间件·架构
小股虫5 小时前
RabbitMQ深度解析:从入门到原理再到实战应用
分布式·rabbitmq
zzhongcy5 小时前
RocketMQ、Kafka 和 RabbitMQ 等中间件对比
kafka·rabbitmq·rocketmq