Commit 1d239c98776b22d055550a8b4db708e3d974efd7
1 parent
bf707077
修改 rabbitmq 序列化方式,使用 Jackson2JsonMessageConverter 替代
Showing
1 changed file
with
9 additions
and
10 deletions
yudao-framework/yudao-spring-boot-starter-mq/src/main/java/cn/iocoder/yudao/framework/mq/rabbitmq/config/YudaoRabbitMQAutoConfiguration.java
| 1 | package cn.iocoder.yudao.framework.mq.rabbitmq.config; | 1 | package cn.iocoder.yudao.framework.mq.rabbitmq.config; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.util.ReflectUtil; | ||
| 4 | import lombok.extern.slf4j.Slf4j; | 3 | import lombok.extern.slf4j.Slf4j; |
| 5 | -import org.springframework.amqp.utils.SerializationUtils; | 4 | +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; |
| 5 | +import org.springframework.amqp.support.converter.MessageConverter; | ||
| 6 | import org.springframework.boot.autoconfigure.AutoConfiguration; | 6 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | 7 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| 8 | - | ||
| 9 | -import java.lang.reflect.Field; | 8 | +import org.springframework.context.annotation.Bean; |
| 10 | 9 | ||
| 11 | /** | 10 | /** |
| 12 | * RabbitMQ 消息队列配置类 | 11 | * RabbitMQ 消息队列配置类 |
| @@ -18,12 +17,12 @@ import java.lang.reflect.Field; | @@ -18,12 +17,12 @@ import java.lang.reflect.Field; | ||
| 18 | @ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate") | 17 | @ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate") |
| 19 | public class YudaoRabbitMQAutoConfiguration { | 18 | public class YudaoRabbitMQAutoConfiguration { |
| 20 | 19 | ||
| 21 | - static { | ||
| 22 | - // 强制设置 SerializationUtils 的 TRUST_ALL 为 true,避免 RabbitMQ Consumer 反序列化消息报错 | ||
| 23 | - // 为什么不通过设置 spring.amqp.deserialization.trust.all 呢?因为可能在 SerializationUtils static 初始化后 | ||
| 24 | - Field trustAllField = ReflectUtil.getField(SerializationUtils.class, "TRUST_ALL"); | ||
| 25 | - ReflectUtil.removeFinalModify(trustAllField); | ||
| 26 | - ReflectUtil.setFieldValue(SerializationUtils.class, trustAllField, true); | 20 | + /** |
| 21 | + * Jackson2JsonMessageConverter Bean:使用 jackson 序列化消息 | ||
| 22 | + */ | ||
| 23 | + @Bean | ||
| 24 | + public MessageConverter createMessageConverter() { | ||
| 25 | + return new Jackson2JsonMessageConverter(); | ||
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | } | 28 | } |