|
@@ -14,6 +14,8 @@ import org.springframework.amqp.support.converter.MessageConverter;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.context.annotation.PropertySource;
|
|
|
|
+import org.springframework.core.env.Environment;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 队列相关配置
|
|
* 队列相关配置
|
|
@@ -23,24 +25,42 @@ import org.springframework.context.annotation.Configuration;
|
|
* 2021-08-26 17:07
|
|
* 2021-08-26 17:07
|
|
*/
|
|
*/
|
|
@Configuration
|
|
@Configuration
|
|
|
|
+@PropertySource(value = {"classpath:conf/mq.properties"})
|
|
public class RabbitMQConfig {
|
|
public class RabbitMQConfig {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private CustomRabbitMQProperties customRabbitMQProperties;
|
|
|
|
|
|
+ private Environment environment;
|
|
|
|
+
|
|
|
|
+ @Bean
|
|
|
|
+ public CustomRabbitMQProperties customRabbitMQProperties () {
|
|
|
|
+ CustomRabbitMQProperties customRabbitMQProperties = new CustomRabbitMQProperties();
|
|
|
|
+ customRabbitMQProperties.setUsername(environment.getProperty("mq.username"));
|
|
|
|
+ customRabbitMQProperties.setPassword(environment.getProperty("mq.password"));
|
|
|
|
+ customRabbitMQProperties.setHost(environment.getProperty("mq.host"));
|
|
|
|
+ customRabbitMQProperties.setPort(Integer.parseInt(environment.getProperty("mq.port")));
|
|
|
|
+ customRabbitMQProperties.setVirtualHost(environment.getProperty("mq.virtual.host"));
|
|
|
|
+ customRabbitMQProperties.setChannelCacheSize(Integer.parseInt(environment.getProperty("mq.channel.cache.size")));
|
|
|
|
+ customRabbitMQProperties.setOpen(Boolean.parseBoolean(environment.getProperty("mq.ope")));
|
|
|
|
+ customRabbitMQProperties.setE_normal_oms_order_to_handle_customs_clearance(environment.getProperty("e.normal.oms.order.to.handle.customs.clearance"));
|
|
|
|
+ customRabbitMQProperties.setQ_normal_oms_order_to_handle_customs_clearance(environment.getProperty("q.normal.oms.order.to.handle.customs.clearance"));
|
|
|
|
+ customRabbitMQProperties.setK_normal_oms_order_to_handle_customs_clearance(environment.getProperty("k.normal.oms.order.to.handle.customs.clearance"));
|
|
|
|
+
|
|
|
|
+ return customRabbitMQProperties;
|
|
|
|
+ }
|
|
|
|
|
|
/* ----------------------------------------------- 基础配置 --------------------------------------------- */
|
|
/* ----------------------------------------------- 基础配置 --------------------------------------------- */
|
|
@Bean
|
|
@Bean
|
|
public ConnectionFactory connectionFactory () {
|
|
public ConnectionFactory connectionFactory () {
|
|
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
|
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
|
- connectionFactory.setUsername(customRabbitMQProperties.getUsername());
|
|
|
|
- connectionFactory.setPassword(customRabbitMQProperties.getPassword());
|
|
|
|
- connectionFactory.setHost(customRabbitMQProperties.getHost());
|
|
|
|
- connectionFactory.setVirtualHost(customRabbitMQProperties.getVirtualHost());
|
|
|
|
- connectionFactory.setPort(customRabbitMQProperties.getPort());
|
|
|
|
|
|
+ connectionFactory.setUsername(customRabbitMQProperties().getUsername());
|
|
|
|
+ connectionFactory.setPassword(customRabbitMQProperties().getPassword());
|
|
|
|
+ connectionFactory.setHost(customRabbitMQProperties().getHost());
|
|
|
|
+ connectionFactory.setVirtualHost(customRabbitMQProperties().getVirtualHost());
|
|
|
|
+ connectionFactory.setPort(customRabbitMQProperties().getPort());
|
|
// 共用同一个Channel
|
|
// 共用同一个Channel
|
|
connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CHANNEL);
|
|
connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CHANNEL);
|
|
// 获取配置的Channel缓存大小
|
|
// 获取配置的Channel缓存大小
|
|
- connectionFactory.setChannelCacheSize(customRabbitMQProperties.getChannelCacheSize());
|
|
|
|
|
|
+ connectionFactory.setChannelCacheSize(customRabbitMQProperties().getChannelCacheSize());
|
|
// 消息到达broke后触发回调
|
|
// 消息到达broke后触发回调
|
|
connectionFactory.setPublisherConfirms(true);
|
|
connectionFactory.setPublisherConfirms(true);
|
|
return connectionFactory;
|
|
return connectionFactory;
|
|
@@ -87,8 +107,8 @@ public class RabbitMQConfig {
|
|
public RabbitTemplate clearRabbitTemplate (ConnectionFactory connectionFactory) {
|
|
public RabbitTemplate clearRabbitTemplate (ConnectionFactory connectionFactory) {
|
|
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
|
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
|
|
|
|
|
- rabbitTemplate.setExchange(customRabbitMQProperties.getE_normal_oms_order_to_handle_customs_clearance());
|
|
|
|
- rabbitTemplate.setRoutingKey(customRabbitMQProperties.getK_normal_oms_order_to_handle_customs_clearance());
|
|
|
|
|
|
+ rabbitTemplate.setExchange(customRabbitMQProperties().getE_normal_oms_order_to_handle_customs_clearance());
|
|
|
|
+ rabbitTemplate.setRoutingKey(customRabbitMQProperties().getK_normal_oms_order_to_handle_customs_clearance());
|
|
rabbitTemplate.setConfirmCallback(new SimpleClearConfirmCallback());
|
|
rabbitTemplate.setConfirmCallback(new SimpleClearConfirmCallback());
|
|
rabbitTemplate.setReturnCallback(new SimpleClearReturnCallback());
|
|
rabbitTemplate.setReturnCallback(new SimpleClearReturnCallback());
|
|
|
|
|
|
@@ -97,16 +117,16 @@ public class RabbitMQConfig {
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
public DirectExchange clearDirectExchange () {
|
|
public DirectExchange clearDirectExchange () {
|
|
- return new DirectExchange(customRabbitMQProperties.getE_normal_oms_order_to_handle_customs_clearance());
|
|
|
|
|
|
+ return new DirectExchange(customRabbitMQProperties().getE_normal_oms_order_to_handle_customs_clearance());
|
|
}
|
|
}
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
public Queue clearQueue () {
|
|
public Queue clearQueue () {
|
|
- return new Queue(customRabbitMQProperties.getQ_normal_oms_order_to_handle_customs_clearance());
|
|
|
|
|
|
+ return new Queue(customRabbitMQProperties().getQ_normal_oms_order_to_handle_customs_clearance());
|
|
}
|
|
}
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
public Binding clearBinding () {
|
|
public Binding clearBinding () {
|
|
- return BindingBuilder.bind(clearQueue()).to(clearDirectExchange()).with(customRabbitMQProperties.getK_normal_oms_order_to_handle_customs_clearance());
|
|
|
|
|
|
+ return BindingBuilder.bind(clearQueue()).to(clearDirectExchange()).with(customRabbitMQProperties().getK_normal_oms_order_to_handle_customs_clearance());
|
|
}
|
|
}
|
|
}
|
|
}
|