Query Kafka Data: Console Consumer Guide
In Kafka, you can use the Kafka command line tool kafka-console-consumer to query specific data. Here are the steps to query specific data using kafka-console-consumer.
- Open the terminal and run the following command to connect to the Kafka server:
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic <topic-name> --from-beginning
- Replace with the topic name you want to search.
- The above command allows you to view all messages of a specified topic. If you only want to query specific messages, you can use the –partition and –offset parameters to specify the partition and offset, for example:
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic <topic-name> --partition <partition-number> --offset <offset-number>
- The sum is the partition and offset to be queried.
By following the steps above, you can query specific data and view the corresponding message content.