Skip to content

Instantly share code, notes, and snippets.

@rmoff
Last active January 5, 2024 19:59
Show Gist options
  • Save rmoff/765c5104f40bdc88ea7ea65dcabb67f6 to your computer and use it in GitHub Desktop.
Save rmoff/765c5104f40bdc88ea7ea65dcabb67f6 to your computer and use it in GitHub Desktop.
Show last three messages from a Kafka topic with kafkacat
kafkacat -b localhost:9092 \
         -t _kafka-connect-group-01-status \
         -C \
         -o-3 \
         -c3 \
         -f 'Topic %t / Partition %p / Offset: %o / Timestamp: %T\nHeaders: %h\nKey (%K bytes): %k\nPayload (%S bytes): %s\n--\n'

Where:

-b

Broker address

-t

Topic name

-C

Run as a consumer (-P for producer)

-o-3

From offset (-o) three from the end (-3).

-c3

Consume three messages and exit (omit this to continue displaying new messages)

-f

Optional format string to display rich information about the message and its metadata.

Useful when starting to poke around topic structures :)

asciicast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment