【问题标题】:get only one record from kafka offset从 kafka 偏移中只获取一条记录
【发布时间】:2021-06-16 09:59:05
【问题描述】:

我知道可以通过在 kafka-console-consumer 中使用 --offset 从特定偏移量从 kafka 读取数据,但这会给出从该特定偏移量到当前偏移量的记录。如何将其限制为仅一条记录。

【问题讨论】:

    标签: apache-kafka kafka-consumer-api


    【解决方案1】:

    如果您在kafka-console-consumer 命令上使用--help,您可以看到:

    --max-messages <Integer: num_messages>   The maximum number of messages to      
                                               consume before exiting. If not set,  
                                               consumption is continual.            
    --offset <String: consume offset>        The offset id to consume from (a non-  
                                               negative number), or 'earliest'      
                                               which means from beginning, or       
                                               'latest' which means from end        
                                               (default: latest)       
    

    --max-messages 设置为 1 就是你想要的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      相关资源
      最近更新 更多