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

发送成功

相关推荐
深蓝电商API10 小时前
Redis 在分布式爬虫中的作用
redis·分布式·爬虫
凤山老林10 小时前
高可用分布式任务调度架构:Spring Boot 集成 PowerJob 实战指南
spring boot·分布式·架构
Dreams_l13 小时前
如何保证RabbitMQ消息可靠传输
java·rabbitmq·java-rabbitmq
海宇数据14 小时前
零信任架构实战:基于海宇运营商近3个月平均账单构建自动化分布式租赁网关
人工智能·分布式·架构·自动化
IT大白鼠15 小时前
MySQL 分布式集群系列 · 第二篇:架构深度拆解--NDB 三大核心节点
分布式·mysql·架构
醉颜凉15 小时前
Kafka ISR与AR深度解析:副本同步机制核心概念
分布式·架构·kafka·ar
johnny23315 小时前
大模型分布式训练理论和框架:DeepSpeed、Megatron、Torchrun
分布式
倔强的石头10618 小时前
高可用与无感扩容——分布式时序数据库选型指南
数据库·分布式·时序数据库
fastjson_2 天前
Spark 安装和使用
大数据·分布式·spark
spter。2 天前
从一次关注到最终一致:Canal、Outbox 与 Kafka 如何解决关系链双写问题
分布式·kafka