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

发送成功

相关推荐
宸津-代码粉碎机1 小时前
OpenAI 连夜迎战 Grok Bot 和 Muse:AI 智能体从 “会聊天” 到 “能办事”,现在入场还来得及吗
java·大数据·人工智能·分布式·python
程序猿乐锅2 小时前
【黑马点评 | 第八篇】Redisson分布式锁
java·数据库·spring boot·redis·分布式·spring·缓存
ly76893 小时前
RabbitMQ 消费确认与预取:manual ack、reject、nack 与 QoS 的取舍
rabbitmq·死信队列·消息可靠性·消费确认·qos 预取
灯澜忆梦4 小时前
【RabbitMQ #7】 | 消息转换器
分布式·rabbitmq·ruby
需要8264 小时前
分布式事务:Seata AT/TCC/SAGA 的取舍与踩坑
java·spring boot·分布式·spring·spring cloud
CS创新实验室7 小时前
为什么三台机器就能选出一个“带头大哥“?——Raft 一致性算法,一次讲透
分布式·操作系统
本人手速666+9 小时前
企微开发API如何设计客户冻结状态?WeComApi 在删除、投诉和异常客户场景中的自动化边界
运维·分布式·自动化·企业微信·企微外部群开发·wecomapi·企业微信二次开发
灯澜忆梦10 小时前
【RabbitMQ #4】 | Work 任务模型
分布式·rabbitmq
程序猿乐锅10 小时前
【黑马点评 | 第七篇】Redis 分布式锁的两种实现
java·数据库·redis·分布式·spring·缓存
千里码aicood12 小时前
基于Hadoop的机票价格波动分析系统的设计与实现
大数据·hadoop·分布式