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

发送成功

相关推荐
邂逅星河浪漫6 小时前
【RabbitMQ】消息队列·详解+实操演示+功能实现(微服务架构)
rabbitmq·springboot·springamqp·consumer·exchange·producer·queue
小马哥编程12 小时前
【软考架构】案例分析-分布式锁
分布式·架构
necessary65312 小时前
从工行“余额归零”事件看CAP定理:当金融系统在一致性与可用性之间做出选择
分布式·金融·wpf·可用性测试
维尔切12 小时前
Kafka 概述与安装部署整理
运维·分布式·kafka
huihuihuanhuan.xin13 小时前
后端八股之消息队列
java·rabbitmq
罗不俷14 小时前
【Hadoop】Hadoop 起源与核心组件解析 —— 大数据时代的分布式基石
大数据·hadoop·分布式
不会写代码的ys17 小时前
仿RabbitMQ实现消息队列(二)-安装
服务器·分布式·rabbitmq
Microsoft Word17 小时前
Rabbitmq基础篇
网络·分布式·rabbitmq
csdn_aspnet17 小时前
.NETCore、.NET 7 和 RabbitMQ 的发布-订阅模式
rabbitmq·.netcore·.net7.
csdn_aspnet17 小时前
RabbitMQ简介
rabbitmq