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

发送成功

相关推荐
是阿威啊5 分钟前
【第三站】本地虚拟机部署hive集群
linux·数据仓库·hive·hadoop·分布式
云技纵横13 分钟前
本地限流与 Redis 分布式限流的无缝切换 技术栈:Sentinel 线程池隔离 + Nginx + Kafka
redis·分布式·sentinel
赵榕26 分钟前
RabbitMQ发布订阅模式多实例消费者防止重复消费实现方式
微服务·消息队列·rabbitmq
源代码•宸30 分钟前
goframe框架签到系统项目开发(分布式 ID 生成器、雪花算法、抽离业务逻辑到service层)
经验分享·分布式·mysql·算法·golang·雪花算法·goframe
初级炼丹师(爱说实话版)1 小时前
ROS分布式通信和Socket.io通信的区别
分布式
阿方索1 小时前
Ceph 分布式存储
分布式·ceph
武子康1 小时前
Java-211 Spring Boot 2.4.1 整合 RabbitMQ 实战:DirectExchange + @RabbitListener 全流程
java·spring boot·分布式·消息队列·rabbitmq·rocketmq·java-rabbitmq
Wang's Blog1 小时前
Kafka: 生产者(Producer)核心机制
分布式·kafka
与遨游于天地1 小时前
日志系统 Kafka 积压处理有效方案
经验分享·分布式·kafka