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

发送成功

相关推荐
拾忆,想起39 分钟前
Dubbo分组(Group)使用指南:实现服务接口的多版本管理与环境隔离
分布式·微服务·性能优化·架构·dubbo
回家路上绕了弯1 小时前
彻底解决超卖问题:从单体到分布式的全场景技术方案
分布式·后端
2501_941802481 小时前
智慧教育平台中的多语言语法引擎与实时学习分析实践
rabbitmq
2501_941810831 小时前
Rust高性能Web后端服务开发与Actix-Web实战分享:零成本抽象、高并发处理与内存安全实践
rabbitmq
2501_941144031 小时前
人工智能赋能智慧安全互联网应用:智能监控与安全防护优化实践探索
rabbitmq
拾忆,想起2 小时前
Dubbo动态配置实时生效全攻略:零停机实现配置热更新
分布式·微服务·性能优化·架构·dubbo
2501_941143325 小时前
微服务架构与服务网格在高并发互联网系统中的优化与工程实践经验分享
rabbitmq
2501_941871456 小时前
C++结合Redis与WebSocket构建高并发实时在线游戏服务设计与实战分享:成都多人竞技游戏架构优化经验
rabbitmq
2501_9418705610 小时前
多语言微服务架构下的分布式事务管理与最终一致性实践
rabbitmq
2501_9418787410 小时前
智能推荐系统与多语言微服务实现:Python、Java、C++与Go全栈开发实战
rabbitmq