交换机和队列的声明一般写在消费者模块里
代码示例:
package com.itheima.config_RabbitMQ;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FanoutConfiguration {
@Bean
public FanoutExchange fanoutExchange() { //创建交换机
//方法一
return ExchangeBuilder.fanoutExchange("hmall.fanout2").build();
//方法二
//return new FanoutExchange("hmall.fanout2");
}
@Bean
public Queue fanoutQueue() { //创建队列
//方法一
return QueueBuilder.durable("fanout.queue3").build();
//方法二
//return new Queue("fanout.queue3");
}
@Bean
public Queue fanoutQueue4() { //创建队列
return QueueBuilder.durable("fanout.queue4").build();
}
@Bean
public Binding fanoutBinding(Queue fanoutQueue, FanoutExchange fanoutExchange) { //绑定交换机、队列 方法一
return BindingBuilder.bind(fanoutQueue).to(fanoutExchange);
}
@Bean
public Binding fanoutBinding2() { //绑定交换机、队列 方法二
return BindingBuilder.bind(fanoutQueue4()).to(fanoutExchange());
}
}
标签:return,队列,fanoutExchange,RabbitMQ,Bean,交换机,Java,public From: https://www.cnblogs.com/gagaya2/p/17872234.html