java应用程序在重新启动时重新使用整个kafka主题

llmtgqce  于 2021-07-15  发布在  Kafka
关注(0)|答案(0)|浏览(250)

我用KafkaReact器做Spring。当我们使用 auto.offset.reset = latest 应用程序将重新启动并重新消耗大量消息。我甚至不能完全肯定这是从一开始,但肯定是他们很多。
为什么会这样?我以为偏移量重置为最新值可以避免这种情况。另外,我的理解是,该设置仅适用于偏移丢失的情况。另一个选择是应用程序从未真正提交?这是使用者配置:

allow.auto.create.topics = true
    auto.commit.interval.ms = 5000
    auto.offset.reset = latest
    bootstrap.servers = [xxx]
    check.crcs = true
    client.dns.lookup = default
    client.id = 
    client.rack = 
    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 = pdp-fragments-group
    group.instance.id = null
    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 = 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 = SSL
    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 = [hidden]
    ssl.keymanager.algorithm = SunX509
    ssl.keystore.location = xxx
    ssl.keystore.password = [hidden]
    ssl.keystore.type = JKS
    ssl.protocol = TLS
    ssl.provider = null
    ssl.secure.random.implementation = null
    ssl.trustmanager.algorithm = PKIX
    ssl.truststore.location = config/kafkakeys/KafkaCaCerts.jks
    ssl.truststore.password = [hidden]
    ssl.truststore.type = JKS
    value.deserializer = class org.apache.kafka.common.serialization.StringDeserializer

代码:

public Flux<ReceiverRecord<String, String>> makeReceiverFlux() {
        var receiverOptions = ReceiverOptions.<String, String>create(consumerProps)
                .subscription(Collections.singletonList(topic));
        var kafkaReceiver = KafkaReceiver.create(receiverOptions);
        return Flux.defer(kafkaReceiver::receive);
    }

    public Flux<ReceiverRecord<String, String>> transformAndCommitKafkaMessages(Flux<ReceiverRecord<String, String>> kafkaFlux,
                                                                                RecordsProcessor recordProcessor) {
        return parallelise(kafkaFlux, recordProcessor);

    }

    Flux<ReceiverRecord<String, String>> parallelise(Flux<ReceiverRecord<String, String>> kafkaFlux,
                                                     RecordsProcessor recordsProcessor) {
        return kafkaFlux.groupBy(msg -> msg.partition() % nWorkers)
                .flatMap(groupedFlux -> groupedFlux.publishOn(this.scheduler)
                        .flatMap(record -> measureTime(process(recordsProcessor, record)))
                        .sample(Duration.ofSeconds(commitIntervalSeconds))
                        .concatMap(record -> commitRecord(record)));
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题