当前位置:网站首页>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
边栏推荐
- 【云原生 | 从零开始学Kubernetes】八、命名空间资源配额以及标签
- Socket error Event: 32 Error: 10053. Connection closing...Socket close
- Recommended system topic | Minet: cross domain CTR prediction
- When the V100 of mindpole 8 card is trained to 101 epochs, an error of reading data timeout is reported
- CarSim simulation quick start (16) - ADAS sensor objects of CarSim sensor simulation (2)
- MySQL date [plus sign / +] condition filtering problem
- 03 isomorphism of tree 1
- Error when creating dataset with mindscore
- Recommended books | essentials of industrial digital transformation: methods and Practice
- MySQL 日期【加号/+】条件筛选问题
猜你喜欢
![[advanced mathematics] [8] differential equation](/img/83/b6b07540e3cf6d6433e57447d42ee9.png)
[advanced mathematics] [8] differential equation
![[advanced mathematics] [1] function, limit, continuity](/img/c5/f9fd3814a61d0fba24b37253c7e51c.png)
[advanced mathematics] [1] function, limit, continuity

Application of conductive slip ring in mechanical equipment

Recommended books | essentials of industrial digital transformation: methods and Practice

PMP每日一练 | 考试不迷路-7.25
![[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day](/img/7d/7a01c8c6923077d6c201bf1ae02c8c.png)
[today in history] July 5: the mother of Google was born; Two Turing Award pioneers born on the same day

9. < tag dynamic programming and subsequence, subarray> lt.718. Longest repeated subarray + lt.1143. Longest common subsequence
![[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger](/img/14/f2b68dbe4e6a9b8d89ed9ff38f5e11.png)
[today in history] July 8: PostgreSQL release; SUSE acquires the largest service provider of k8s; Activision Blizzard merger

雷达水位计的工作原理及安装维护注意事项

PyTorch 模型 onnx 文件的导出和调用
随机推荐
【NOI模拟赛】字符串匹配(后缀自动机SAM,莫队,分块)
Dataloader reports an error "default_collate: batch must contain tensors, numpy arrays, numbers, dicts" when pytorch trains the model
Timing analysis and constraints based on xlinx (1) -- what is timing analysis? What are temporal constraints? What is temporal convergence?
Can you tell me whether mindspore supports torchvision Model directly uses the pre trained network, such as vgg16
What is the method to load the torch pre trained model for the mindspore model finetune?
各厂商网络虚拟化的优势
Digital informatization (enumerate assumptions first, and then see whether the conditions are met) (1089 werewolf kill - simple version)
【高等数学】【8】微分方程
Docker builds redis cluster
什么是聚类分析?聚类分析方法的类别[通俗易懂]
【高等数学】【1】函数、极限、连续
CarSim仿真快速入门(十六)—CarSim传感器仿真之ADAS Sensor Objects (2)
Prescan quick start to master the special functions of prescan track editing in lecture 18
4、Nacos 配置中心源码解析之 服务端启动
[today in history] July 18: Intel was founded; The first photo was posted on the world wide web; EBay spins off PayPal
[Infographics Show] 248 Public Domain Name
随机梯度下降法、牛顿法、冲量法、AdaGrad、RMSprop以及Adam优化过程和理解
Summarize the level of intelligent manufacturing discussion [macro understanding]
Array of sword finger offer question bank summary (I) (C language version)
移动web布局方法