|
@@ -2,7 +2,16 @@ package com.abi.qms.platform.infrastructure.config;
|
|
|
|
|
|
import com.abi.qms.platform.infrastructure.mq.TableStoreBatchInsertConsumer;
|
|
|
import com.abi.qms.platform.infrastructure.mq.TableStoreBatchUpdateConsumer;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.core.Queue;
|
|
|
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
+import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
+import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
@@ -13,6 +22,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
* @date: 2021-05-11
|
|
|
*/
|
|
|
@Configuration
|
|
|
+@Slf4j
|
|
|
public class RabbitmqConfig {
|
|
|
|
|
|
@Bean(name = "qms_table_store_queue")
|
|
@@ -25,4 +35,37 @@ public class RabbitmqConfig {
|
|
|
return new Queue(TableStoreBatchUpdateConsumer.TABLE_STORE_BATCH_UPDATE_QUEUE);
|
|
|
}
|
|
|
|
|
|
+ @Value("${spring.rabbitmq.addresses}")
|
|
|
+ private String addresses;
|
|
|
+ @Value("${spring.rabbitmq.username}")
|
|
|
+ private String username;
|
|
|
+ @Value("${spring.rabbitmq.password}")
|
|
|
+ private String password;
|
|
|
+ @Value("${spring.rabbitmq.virtual-host}")
|
|
|
+ private String virtualHost;
|
|
|
+
|
|
|
+ @Bean("qmsConnectionFactory")
|
|
|
+ public ConnectionFactory connectionFactory() {
|
|
|
+ CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
|
|
+ connectionFactory.setAddresses(addresses);
|
|
|
+ connectionFactory.setUsername(username);
|
|
|
+ connectionFactory.setPassword(password);
|
|
|
+ connectionFactory.setVirtualHost(virtualHost);
|
|
|
+ connectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.SIMPLE);
|
|
|
+ connectionFactory.setPublisherReturns(true);
|
|
|
+ return connectionFactory;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(name = "qmsRabbitTemplate")
|
|
|
+ public RabbitTemplate rabbitTemplate(){
|
|
|
+ RabbitTemplate template = new RabbitTemplate(this.connectionFactory());
|
|
|
+ template.setMessageConverter(new Jackson2JsonMessageConverter());
|
|
|
+ template.setMandatory(true);
|
|
|
+ template.setConfirmCallback((CorrelationData correlationData, boolean ack, String cause) ->
|
|
|
+ log.info("CorrelationData:{}, ack:{}, cause:{}", correlationData, ack, cause));
|
|
|
+ template.setReturnCallback((Message message, int replyCode, String replyText, String exchange, String routingKey) ->
|
|
|
+ log.info("message:{}, replyCode:{}, replyText:{}, exchange:{}, routingKey:{}", message, replyCode, replyText, exchange, routingKey));
|
|
|
+ return template;
|
|
|
+ }
|
|
|
+
|
|
|
}
|