下面是我得到的错误:
org.apache.kafka.common.errors.SerializationException: Error deserializing
key/value for partition distance-0 at offset 0. If needed, please seek past
the record to continue consumption.
Caused by: java.lang.IllegalStateException: No type information in headers
and no default type provided
at org.springframework.util.Assert.state(Assert.java:73)
at org.
springframework.kafka.support.serializer.jsondesializer.deserialize(jsondesializer)。java:370)
和应用程序-dev.yml:
spring:
json:
use:
type:
headers: false
value:
default:
type: Object
method: com.mycompany.mypackage.KafkaConfig.returnType
还尝试了:
consumer:
bootstrap-servers: 10.10.5.189:9092
value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
enable-auto-commit: false
auto-offset-reset: earliest
properties:
spring:
json:
trusted:
packages: '*'
value:
default:
method: com.mycompany.mypackage.KafkaConfig.returnTypee
并没有任何警告,但我把printlin放在静态方法中,它从来并没有触发过?有什么好处?
@KafkaListener(topics = "distance", groupId = "${kafka.myinfo.id}")
public void handle(CustDeletedEvent custDeletedEvent) {
log.debug("received jsonNode: "+ userDeletedEvent);
Kafka图.java
// NEVER CALLED!!!
public static JavaType returnType(byte[] data, Headers headers) {
System.out.println("return type called data.length="+data.length);
JavaType custDeletedEvent =
TypeFactory.defaultInstance().constructType(CustDeletedEvent.class);
return custDeletedEvent;
}
最新配置:
kafka:
bootstrap-servers: 10.10.5.189:9092
producer:
bootstrap-servers: 10.10.5.189:9092
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
consumer:
bootstrap-servers: 10.10.5.189:9092
value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
enable-auto-commit: false
auto-offset-reset: earliest
properties:
spring:
json:
trusted:
packages: '*'
value:
method: mypackage.config.KafkaConfig.returnType
SpringKafka配置在这里
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
以下是确切的yaml:
spring:
profiles:
active: dev
kafka:
bootstrap-servers: 10.10.5.189:9092
producer:
bootstrap-servers: 10.10.5.189:9092
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
consumer:
bootstrap-servers: 10.10.5.189:9092
value-deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
enable-auto-commit: false
auto-offset-reset: earliest
properties:
spring:
json:
trusted:
packages: '*'
value:
method: com.service.cust.impl.returnType
1条答案
按热度按时间jjhzyzn01#
它需要进去
spring.kafka.consumer.properties.spring.json...
.