mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
rabbitmq配置支持publicKey解密
This commit is contained in:
+41
@@ -1,18 +1,28 @@
|
||||
package com.cf.imes.framework.mq.rabbitmq.config;
|
||||
|
||||
import com.cf.imes.framework.common.util.encrypt.AesUtils;
|
||||
import com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.core.QueueBuilder;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.amqp.CachingConnectionFactoryConfigurer;
|
||||
import org.springframework.boot.autoconfigure.amqp.ConnectionFactoryCustomizer;
|
||||
import org.springframework.boot.autoconfigure.amqp.RabbitConnectionFactoryBeanConfigurer;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -31,6 +41,37 @@ import static com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants.ORDER
|
||||
@ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate")
|
||||
public class ChenfengRabbitMQAutoConfiguration {
|
||||
|
||||
@Value("${chenfeng.encrypt.publicKey:}")
|
||||
private String publicKey;
|
||||
|
||||
/**
|
||||
* 参考 org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration 的 rabbitConnectionFactory 方法
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
CachingConnectionFactory rabbitConnectionFactory(
|
||||
RabbitConnectionFactoryBeanConfigurer rabbitConnectionFactoryBeanConfigurer,
|
||||
CachingConnectionFactoryConfigurer rabbitCachingConnectionFactoryConfigurer,
|
||||
ObjectProvider<ConnectionFactoryCustomizer> connectionFactoryCustomizers) throws Exception {
|
||||
|
||||
RabbitConnectionFactoryBean connectionFactoryBean = new RabbitConnectionFactoryBean();
|
||||
rabbitConnectionFactoryBeanConfigurer.configure(connectionFactoryBean);
|
||||
connectionFactoryBean.afterPropertiesSet();
|
||||
com.rabbitmq.client.ConnectionFactory connectionFactory = connectionFactoryBean.getObject();
|
||||
|
||||
if (StringUtils.isNotEmpty(publicKey)) {
|
||||
connectionFactory.setUsername(AesUtils.decrypt(connectionFactory.getUsername(), publicKey));
|
||||
connectionFactory.setPassword(AesUtils.decrypt(connectionFactory.getPassword(), publicKey));
|
||||
}
|
||||
connectionFactoryCustomizers.orderedStream()
|
||||
.forEach((customizer) -> customizer.customize(connectionFactory));
|
||||
|
||||
CachingConnectionFactory factory = new CachingConnectionFactory(connectionFactory);
|
||||
rabbitCachingConnectionFactoryConfigurer.configure(factory);
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Jackson2JsonMessageConverter Bean:使用 jackson 序列化消息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user