如何使用偏移值从服务器消费kafka消息?

How to consume kafka message from server with offset value?

我正在使用 ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topicName --from-beginning --max-messages 10

它给了我 10 条消息,但我希望该消息具有特定的消息偏移值,例如:

kafka-message 1234 其中kafka-message是kafka消息,1234是偏移值。

可能吗?

使用kafkacat -f '%s %o'

Format string tokens:
  %s                 Message payload
  %S                 Message payload length (or -1 for NULL)
  %R                 Message payload length (or -1 for NULL) serialized
                     as a binary big endian 32-bit signed integer
  %k                 Message key
  %K                 Message key length (or -1 for NULL)
  %T                 Message timestamp (milliseconds since epoch UTC)
  %h                 Message headers (n=v CSV)
  %t                 Topic
  %p                 Partition
  %o                 Message offset
  \n \r \t           Newlines, tab
  \xXX \xNNN         Any ASCII character
 Example:
  -f 'Topic %t [%p] at offset %o: key %k: %s\n'