当前位置:网站首页>FanoutExchange交换机代码教程
FanoutExchange交换机代码教程
2022-07-25 20:20:00 【Max恒】
源码在文章末尾
1. 在consumer服务声明Exchange、Queue、Binding
@Configuration
public class FanoutConfig {
@Bean
public FanoutExchange fanoutExchange(){
// 声明FanoutExchange交换机
return new FanoutExchange("声明FanoutExchange交换机");
}
//声明第一个队列
@Bean
public Queue fanoutQueue1(){
return new Queue("fanout.queue1");
}
//绑定队列1 和交换机 (名称和类型要一致, 会按照这个注入的)
@Bean
public Binding bindingQueue1(Queue fanoutQueue1, FanoutExchange fanoutExchange){
return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
}
//声明第二个队列
@Bean
public Queue fanoutQueue2(){
return new Queue("fanout.queue2");
}
//绑定队列2 和交换机
@Bean
public Binding bindingQueue2(Queue fanoutQueue2, FanoutExchange fanoutExchange){
return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
}
}2. 在consumer服务声明两个消费者
@RabbitListener(queues = "fanout.queue1")
public void listenFanoutQueue1(String msg){
System.out.println("消费者接收到fanout.queue1的消息:【" + msg + "】");
}
@RabbitListener(queues = "fanout.queue2")
public void listenFanoutQueue2(String msg){
System.out.println("消费者接收到fanout.queue2的消息:【" + msg + "】");
}3. 最后开始发送消息测试
@Test
public void testSendFanoutExchange() {
// 交换机名称
String exchangeName = "声明FanoutExchange交换机";
// 消息
String message = "测试 FanoutExchange 交换机, 请各位接收 !";
rabbitTemplate.convertAndSend(exchangeName, "", message);
}最后运行结果
源码项目地址:
链接: https://pan.baidu.com/s/1vnYVEPGO8B5XLCf9Xc67cA 提取码: few9
边栏推荐
- 股票软件开发
- Arrow parquet
- Mindspore1.1.1 source code compilation and installation -- errors in the core compilation stage
- securecrt乱码解决方法[通俗易懂]
- Application of conductive slip ring in mechanical equipment
- Recommendations on how to install plug-ins and baby plug-ins in idea
- Notes - record a cannotfinddatasourceexception: dynamic datasource can not find primary datasource problem solving
- DIY personal server (DIY storage server)
- [today in history] July 2: BitTorrent came out; The commercial system linspire was acquired; Sony deploys Playstation now
- 03 isomorphism of tree 1
猜你喜欢

Vivo official website app full model UI adaptation scheme

Remote monitoring solution of intelligent electronic boundary stake Nature Reserve

Jmeter——接口测试

Notes - record a cannotfinddatasourceexception: dynamic datasource can not find primary datasource problem solving
![[advanced mathematics] [6] differential calculus of multivariate functions](/img/9e/84fe6f74b58cbaabab1b6eed0df556.png)
[advanced mathematics] [6] differential calculus of multivariate functions

Advantages of network virtualization of various manufacturers

当AI邂逅生命健康,华为云为他们搭建三座桥

如何保证定制滑环质量

Technology cloud report: more than zero trust, the wild hope of Parra's "Digital Security Cloud strategy"

Working principle of radar water level gauge and precautions for installation and maintenance
随机推荐
当AI邂逅生命健康,华为云为他们搭建三座桥
[today in history] July 4: the first e-book came out; The inventor of magnetic stripe card was born; Palm computer pioneer was born
Cloud native guide: what is cloud native infrastructure
Notes - record a cannotfinddatasourceexception: dynamic datasource can not find primary datasource problem solving
[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day
When the V100 of mindpole 8 card is trained to 101 epochs, an error of reading data timeout is reported
Link list of sword finger offer question bank summary (III) (C language version)
Redis source code -ziplist
10. < tag dynamic programming and subsequence, subarray> lt.53. maximum subarray and + lt.392. Judge subsequence DBC
[Infographics Show] 248 Public Domain Name
[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger
Google pixel 6A off screen fingerprint scanner has major security vulnerabilities
[today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
4everland storage node portal network design
Error when creating dataset with mindscore
Advantages of network virtualization of various manufacturers
Do you still have certificates to participate in the open source community?
Summarize the level of intelligent manufacturing discussion [macro understanding]
接口请求合并的3种技巧,性能直接爆表!
When AI encounters life and health, Huawei cloud builds three bridges for them