kafka消费端核心参数
所属分类 kafka
浏览量 1048
bootstrap.servers
group.id
fetch.max.bytes 默认1M
max.poll.records 每次poll返回消息的最大条数,默认500
enable.auto.commit 自动提交 offset
auto.commit.interval.ms 每隔多久提交一次offset,默认 5000ms
max.poll.interval.ms 默认300000ms 300秒 5分钟
这个很重要 ,消费处理时间 超过该值 会导致重平衡
connection.max.idle.max
连接最大空闲时间, 建议 -1,不回收连接
auto.offset.reset
earliest offset不存在,从头开始消费
latest offset不存在,从新消息开始消费 ,默认
none offset不存在 ,抛异常
session.timeout.ms
Coordinator 检测消费者失败的时间,在该时间内保持心跳即可
更小的值可以更快发现消费者崩溃,更快地开启重平衡,避免消费滞后,但这会导致频繁重平衡
heartbeat.interval.ms
心跳时间间隔 ,应小于 session.timeout.ms
partition.assignment.strategy = [class org.apache.kafka.clients.consumer.RangeAssignor]
auto.commit.interval.ms = 5000
request.timeout.ms = 305000
connections.max.idle.ms = 540000
fetch.max.wait.ms = 500
heartbeat.interval.ms = 3000
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 305000
retry.backoff.ms = 100
session.timeout.ms = 10000
isolation.level = read_uncommitted
全部参数及默认值
consumer运行时,会输出配置信息
INFO org.apache.kafka.clients.consumer.ConsumerConfig -ConsumerConfig values:
auto.commit.interval.ms = 5000
auto.offset.reset = latest
bootstrap.servers = [127.0.0.1:9092]
check.crcs = true
client.id =
connections.max.idle.ms = 540000
enable.auto.commit = true
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = kafkademo_test_group
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 = 500
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 = 305000
retry.backoff.ms = 100
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.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 = null
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
例子代码
https://gitee.com/dyyx/kafkademo/blob/master/src/main/java/dyyx/ConsumerTest.java
上一篇
下一篇
linux 帮助命令使用
kafka消息存储及索引机制
kafka消费机制要点
kafka消费分区重平衡机制
Kafka网络模型
java nio 编程模型简介