RabbitMq——direct交换器和fanout交换器 扇形交换器

本文详细介绍了如何在RabbitMQ中使用直接交换器和扇形交换器进行消息发送与接收,包括配置发送队列、监听器方法以及创建和绑定交换器的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
发送成功
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值