[英]I've built a kafka consumer that consumes from a topic with a specified groupId. If I changed the groupID to start from offset 0, it doesn't work
在以下方法中,我能夠使用來自“my_topic”的許多消息。 據我了解,如果我想再次從偏移量 0 開始消費,我可以
a) 使用重置偏移量;
kafka-consumer-groups.sh --bootstrap-server xxx:9094 --command-config./xxx --execute --reset-offsets -group my_group -to-earliest
或者... b) 將 groupID 重命名為與“my_group”不同的名稱,例如“my_group_2”。
public class MessageConsumer extends ConsumerBase {
@KafkaListener(topics = "my_topic", groupId = "my_group")
void processReferralEvents(String message) {
log.info("message received: [{}]", message);
當我將 my_group_2 指定為 groupId 時,將創建my_group_2並自動采用my_group的偏移量。
我錯過了一些明顯的東西嗎?
當消費者 groupId 不存在時,消費者將使用auto.offset.reset設置來找到他們的起始位置。 此設置默認為latest
,因此它只會使用主題中的新記錄。
如果你設置auto.offset.reset=earliest
並切換到一個新的 groupId 那么消費者將從第一個可用的偏移量開始(如果保留策略已經從主題中刪除了最舊的記錄,它可能不一定是 0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.