本文介绍了Kafka批处理侦听器不正确的反序列化消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用具有以下配置的批处理侦听,但是我的消息错误地反序列化了:
I am using batch listening with following configuration but my message wrongly deserialise :
@KafkaListener(
id = "${kafka.buyers.product-sales-pricing.id}",
topics = "${kafka.buyers.product-sales-pricing.topic}",
groupId = "${kafka.buyers.group-id}",
concurrency = "${kafka.buyers.concurrency}"
)
public void listen( @Payload List<String> messages,
@Header( KafkaHeaders.RECEIVED_PARTITION_ID ) List<Integer> partitions,
@Header( KafkaHeaders.OFFSET ) List<Long> offsets ) throws IOException
{}
在yml中:
spring:
kafka:
bootstrapServers: localhost:29092
consumer:
enable-auto-commit: false
autoOffsetReset: earliest
keyDeserializer: org.apache.kafka.common.serialization.StringDeserializer
valueDeserializer: org.apache.kafka.common.serialization.StringDeserializer #spring message converter will take care of deserialization
max-poll-records: 5
在上方,我轮询5条消息,但收到的消息超过100条,当我对其进行反序列化时,该消息会在列表中多个显示.
Using above i am polling 5 message but receive more that 100 message and when i check it deserializeone message to multiple in list.
我检查了我的民意调查配置不起作用.谁能建议我解决方案
I checked my poll configuration not working. Can anyone suggest me solution
以下是我的日志:
2019-08-01 20:10:42.777 INFO 2823 --- [ main] o.a.k.clients.consumer.ConsumerConfig : ConsumerConfig values:
auto.commit.interval.ms = 5000
auto.offset.reset = earliest
bootstrap.servers = [localhost:29092]
check.crcs = true
client.id =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = kafka-buyers-consumer-group1
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 5
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
receive.buffer.bytes = 65536
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
send.buffer.bytes = 131072
session.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2, TLSv1.1, TLSv1]
ssl.endpoint.identification.algorithm = https
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLS
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
推荐答案
在您的情况下,您错过了一种用于批量监听的配置:
In your case you missed one configuration for batch listening:
spring:
kafka:
listener:
type: BATCH # this configuration is required in spring boot application without this spring boot return single message(without batch)
fetch-min-size: 10 # without this you will get 1 message some time but this is optional in your case.
我敢打赌,如果您从kafkaListner类中删除列表,那么在您的问题中您的配置将起作用.
I bet that in your problem your configuration will work if you remove List from kafkaListner class.
希望这对您有所帮助.
这篇关于Kafka批处理侦听器不正确的反序列化消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!