refactor(mq): 优化RabbitMQ消息转换器配置
- 移除自定义ObjectMapper实例,改用注入的@Primary ObjectMapper - 删除对JavaTimeModule和序列化配置的显式设置 - 简化messageConverter方法实现,提高配置复用性 - 保持消息转换功能一致性和代码简洁性
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
package com.gxwebsoft.common.mq.config;
|
package com.gxwebsoft.common.mq.config;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
||||||
import org.springframework.amqp.core.*;
|
import org.springframework.amqp.core.*;
|
||||||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
||||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||||
@@ -68,13 +65,7 @@ public class RabbitMQConfig {
|
|||||||
// ==================== Message Converter ====================
|
// ==================== Message Converter ====================
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MessageConverter messageConverter() {
|
public MessageConverter messageConverter(ObjectMapper objectMapper) {
|
||||||
// 使用JacksonConfig中定义的@Primary objectMapper bean
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
objectMapper.registerModule(new JavaTimeModule());
|
|
||||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
|
||||||
objectMapper.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
|
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
return new Jackson2JsonMessageConverter(objectMapper);
|
return new Jackson2JsonMessageConverter(objectMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user