mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
feat(RabbitConfig.java): RabbitMQ添加消息序列化配置
This commit is contained in:
parent
670c3154d1
commit
89fc1ff8c4
@ -4,18 +4,13 @@ import com.youlai.common.rabbitmq.dynamic.RabbitModuleInitializer;
|
||||
import com.youlai.common.rabbitmq.dynamic.RabbitModuleProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.AmqpAdmin;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer;
|
||||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
|
||||
|
||||
/**
|
||||
* @author huawei
|
||||
@ -24,26 +19,24 @@ import org.springframework.messaging.handler.annotation.support.MessageHandlerMe
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RabbitConfig implements RabbitListenerConfigurer{
|
||||
public class RabbitConfig {
|
||||
|
||||
@Override
|
||||
public void configureRabbitListeners(RabbitListenerEndpointRegistrar rabbitListenerEndpointRegistrar) {
|
||||
rabbitListenerEndpointRegistrar.setMessageHandlerMethodFactory(messageHandlerMethodFactory());
|
||||
}
|
||||
|
||||
@Bean
|
||||
MessageHandlerMethodFactory messageHandlerMethodFactory(){
|
||||
DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory();
|
||||
messageHandlerMethodFactory.setMessageConverter(mappingJackson2MessageConverter());
|
||||
return messageHandlerMethodFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MappingJackson2MessageConverter mappingJackson2MessageConverter() {
|
||||
return new MappingJackson2MessageConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息序列化配置
|
||||
*
|
||||
* @param connectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RabbitListenerContainerFactory<?> rabbitListenerContainerFactory(ConnectionFactory connectionFactory) {
|
||||
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory);
|
||||
factory.setMessageConverter(new Jackson2JsonMessageConverter());
|
||||
return factory;
|
||||
}
|
||||
|
||||
/*
|
||||
* 动态创建队列、交换机初始化器
|
||||
*
|
||||
* @return
|
||||
|
Loading…
Reference in New Issue
Block a user