|
@@ -5,11 +5,18 @@ import org.springframework.amqp.core.FanoutExchange;
|
|
|
import org.springframework.amqp.core.Binding;
|
|
|
import org.springframework.amqp.core.Queue;
|
|
|
import org.springframework.amqp.core.TopicExchange;
|
|
|
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
|
|
|
@Configuration
|
|
|
public class MqListeners {
|
|
|
+ @Lazy
|
|
|
+ @Autowired
|
|
|
+ RabbitAdmin rabbitAdmin;
|
|
|
/** 管理用的队列和交换机,主要是平台统一监控: 1.用户进入智能客服;2.用户使用智能客服;3.用户需要转人工; */
|
|
|
/** 管理用 - 交换机 */
|
|
|
public final static String adminExName = "adminEx";
|
|
@@ -91,4 +98,24 @@ public class MqListeners {
|
|
|
return BindingBuilder.bind(chatQueue()).to(exchange()).with(routerMatch);
|
|
|
}
|
|
|
|
|
|
+ // 创建初始化RabbitAdmin对象
|
|
|
+ @Bean
|
|
|
+ public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
|
|
|
+ RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
|
|
+ // 只有设置为 true,spring 才会加载 RabbitAdmin 这个类
|
|
|
+ rabbitAdmin.setAutoStartup(true);
|
|
|
+ return rabbitAdmin;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建交换机和对列
|
|
|
+ @Bean
|
|
|
+ public void createExchangeQueue() {
|
|
|
+ rabbitAdmin.declareExchange(admiExchange());
|
|
|
+ rabbitAdmin.declareExchange(userExchange());
|
|
|
+ rabbitAdmin.declareExchange(exchange());
|
|
|
+
|
|
|
+ rabbitAdmin.declareQueue(adminQueue());
|
|
|
+ rabbitAdmin.declareQueue(userQueue());
|
|
|
+ rabbitAdmin.declareQueue(chatQueue());
|
|
|
+ }
|
|
|
}
|