简体   繁体   English

spring cloud stream kafka binder 以编程方式将 kafka 主题(多个分区)偏移量重置为任意数字

[英]spring cloud stream kafka binder resetting a kafka topic(multiple partitions) offset to an arbitrary number programatically

I have a requirement to reset offset to a number.我需要将偏移量重置为一个数字。

Detailed requirement : My application is consuming messages from kafka topic and dumping it in DB, let's say DB goes down while processing the consumed messages(offset=10) and till the time DB was down the application consumed messages till offset 20.详细要求:我的应用程序正在使用来自 kafka 主题的消息并将其转储到 DB 中,假设 DB 在处理消耗的消息(偏移量 = 10)时关闭,直到 DB 关闭时应用程序消耗消息直到偏移量 20。

Now DB comes up again while processing the 20th offset message, now I want to reset the offset to 10 again so that I can save the data in database.现在 DB 在处理第 20 个偏移消息时再次出现,现在我想再次将偏移重置为 10,以便我可以将数据保存在数据库中。

Can I achieve that programatically (spring boot) ?我可以以编程方式实现(弹簧启动)吗? I am using spring cloud stream binder kafka.我正在使用 spring 云流粘合剂 kafka。

Why continue to receive messages if the DB is down?如果数据库关闭,为什么还要继续接收消息?

Simply configure the listener container to keep retrying the current record until the DB is available again.只需将侦听器容器配置为不断重试当前记录,直到数据库再次可用。

@Bean
ListenerContainerCustomizer<AbstractMessageListenerContainer<?, ?>> listenerContainerCustomizer() {
    return (container, topic, group) -> {
        container.setErrorHandler(...);
    };
}

See https://docs.spring.io/spring-kafka/docs/current/reference/html/#seek-to-currenthttps://docs.spring.io/spring-kafka/docs/current/reference/html/#seek-to-current

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM