|
@@ -0,0 +1,75 @@
|
|
|
+package com.usky.dxtop.service.config.rabbitmq;
|
|
|
+
|
|
|
+import com.usky.dxtop.service.config.RabbitmqConfig;
|
|
|
+import lombok.Data;
|
|
|
+import org.springframework.amqp.core.*;
|
|
|
+import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
|
|
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yq
|
|
|
+ * @date 2021/9/15 10:43
|
|
|
+ */
|
|
|
+@Configuration
|
|
|
+@Data
|
|
|
+public class CardReissueConfig {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RabbitmqConfig rabbitmqConfig;
|
|
|
+ public static final String NAME = "card_reissue_consumer";
|
|
|
+ private final static String MODULE_NAME = "cardReissue";
|
|
|
+
|
|
|
+ private final static String CONNECTION = MODULE_NAME+RabbitmqConfig.CONNECTION;
|
|
|
+ private final static String TEMPLATE = MODULE_NAME+RabbitmqConfig.TEMPLATE;
|
|
|
+ private final static String LISTENER = MODULE_NAME+RabbitmqConfig.LISTENER;
|
|
|
+ private final static String ADMIN = MODULE_NAME+RabbitmqConfig.ADMIN;
|
|
|
+ private final static String EXCHANGE = MODULE_NAME+RabbitmqConfig.EXCHANGE;
|
|
|
+ private final static String QUEUE = MODULE_NAME+RabbitmqConfig.QUEUE;
|
|
|
+ private final static String BINDING = MODULE_NAME+RabbitmqConfig.BINDING;
|
|
|
+
|
|
|
+ @Bean(name = CONNECTION)
|
|
|
+ public ConnectionFactory connectionFactory(){
|
|
|
+ return rabbitmqConfig.connectionFactory(NAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(name = TEMPLATE)
|
|
|
+ public RabbitTemplate rabbitTemplate(@Qualifier(CONNECTION) ConnectionFactory connectionFactory ) {
|
|
|
+ return rabbitmqConfig.rabbitTemplate(connectionFactory);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(name = LISTENER)
|
|
|
+ public SimpleRabbitListenerContainerFactory listenerFactory(
|
|
|
+ SimpleRabbitListenerContainerFactoryConfigurer configurer,
|
|
|
+ @Qualifier(CONNECTION) ConnectionFactory connectionFactory) {
|
|
|
+ return rabbitmqConfig.listenerFactory(configurer,connectionFactory);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(ADMIN)
|
|
|
+ AmqpAdmin amqpAdmin(@Qualifier(CONNECTION) ConnectionFactory connectionFactory) {
|
|
|
+ return new RabbitAdmin(connectionFactory);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(EXCHANGE)
|
|
|
+ public DirectExchange exchange(@Qualifier(ADMIN) AmqpAdmin amqpAdmin) {
|
|
|
+ return rabbitmqConfig.exchange(NAME,amqpAdmin);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(QUEUE)
|
|
|
+ Queue queue(@Qualifier(ADMIN)AmqpAdmin amqpAdmin) {
|
|
|
+ return rabbitmqConfig.queue(NAME,amqpAdmin);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(BINDING)
|
|
|
+ Binding bindingPersonDirect(@Qualifier(ADMIN)AmqpAdmin amqpAdmin) {
|
|
|
+ Binding binding = BindingBuilder.bind(queue(amqpAdmin)).to(exchange(amqpAdmin)).with(NAME);
|
|
|
+ binding.setAdminsThatShouldDeclare(amqpAdmin);
|
|
|
+ return binding;
|
|
|
+ }
|
|
|
+}
|