Spring Boot引入Redis后Kafka事件序列化异常求助
问题:引入Redis缓存后Spring Cloud Stream向Kafka生产事件出现序列化失败
原本使用Spring Cloud Stream向Kafka生产事件功能一切正常,但引入Redis缓存后,Redis缓存功能运行正常,而向Kafka发送事件的功能出现故障,生产事件时抛出如下Redis序列化异常:
Error while producing SampleEvent: org.springframework.messaging.MessageDeliveryException: failed to send Message to channel 'sampleOutput'; nested exception is org.springframework.data.redis.serializer.SerializationException: Could not write JSON: Not an array: {"type":"record","name":"SampleEvent","namespace":"com.sample.redisandkafka","fields":[{"name":"field","type":"string","default":"null"}]} (through reference chain: org.springframework.cloud.schema.registry.ParsedSchema["schema"]->org.apache.avro.Schema$RecordSchema["elementType"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Not an array: {"type":"record","name":"SampleEvent","namespace":"com.sample.redisandkafka","fields":[{"name":"field","type":"string","default":"null"}]} (through reference chain: org.springframework.cloud.schema.registry.ParsedSchema["schema"]->org.apache.avro.Schema$RecordSchema["elementType"]), failedMessage=GenericMessage [payload={"field": "value"}, headers={id=16108acf-6ca1-f1b2-2ed3-44eb857daa6b, contentType=application/*+avro, timestamp=1712741537549}]
使用版本:
- Spring Boot 2.4.5
- Spring Cloud Stream 2020.0.2
验证情况:移除Redis相关依赖及RedisCacheConfig类后,仅保留Kafka功能的应用可正常运行。
移除的依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
移除的配置:
cache: cache-names: sample-cache default-ttl: 1 # TTL in hours enabled: true type: redis host: localhost port: 6379 caches-ttl: # TTL in hours sample-cache: 1
内容的提问来源于stack exchange,提问作者Naveen
相关产品推荐
相关产品推荐

