This is the first day of my participation in Gwen Challenge

Defining global variables

IP="x.x.x.x:2181"
Ktool=/kafka/bin/kafka-topics.sh
Copy the code

Create a topic

if [ $topic != "" ]; then if [ $partitions -lt 50 ]; then ${Ktool} --create --zookeeper ${IP} --replication-factor $factor --partitions $partitions --topic $topic echo $TOPIC $partitions $factor echo "Created successfullyCopy the code

View basic Kafka information

Echo "" echo" "echo" -- -- -- -- -- to display all the topic -- -- -- -- -- "echo" "${Ktool} --list --zookeeper ${IP}Echo "" echo" -- -- -- -- -- to display all topic attributes -- - "echo" "echo" attribute name introduction: "Echo "retention. Ms == Log data retention duration 432,000,000 ms= 5 days" echo "PartitionCount== Total number of slices "echo "ReplicationFactor== Number of data copies to be replicated. Generally, three copies are reserved for two copies, and so on" Echo "Replicas == Replicas "echo "" topics=$(${Ktool} --list --zookeeper ${IP}) for I in ${topics[@]} do if [ "$i" != "__consumer_offsets" ]; then echo "topic: $i"  ${Ktool} --describe --zookeeper  --topic $iFi echo "" done echo "---- Display complete -----" echo"Copy the code

View the maximum and minimum values of Offset

Kclass=/kafka/bin/kafka-run-class.sh echo "topic: $topic"${Kclass} kafka.tools.GetOffsetShell --broker-list ${IP} --topic $topic --time -2Echo "topic: $topic${Kclass} kafka.tools.GetOffsetShell --broker-list ${IP} --topic $topic --time -1
Copy the code

View the latest messages. A maximum of 1000 messages can be displayed

if [ $message -lt 1000 ]; $message" echo "" /kafka/bin/kafka-console-consumer.sh --topic $topic $message" echo "" /kafka/bin/kafka-console-consumer.sh --topic $topic --bootstrap-server ${IP} --max-messages $message echo "" echo "" echo "----- Display complete -----" fiCopy the code

View the maximum number of messages, starting from the minimum value of Offset

if [ $message -lt 1001 ]; $message" echo "" /kafka/bin/kafka-console-consumer.sh --topic $topic --bootstrap-server ${IP} --from-beginning --max-messages $message echo "" echo "----- display complete -----" fiCopy the code

Start to view a maximum of 1000 messages at the Offset position

if [ $offset != "" ]; then if [ $message -lt 1000 ]; Then echo "" echo "topic:$topic,offset: $offset,partition: $partition, $message" /kafka/bin/kafka-console-consumer.sh --topic $topic --bootstrap-server ${IP} --offset $offset --partition $partition --max-messages $message echo "" echo "" fi fiCopy the code

View all consumer groups

echo "" /kafka/bin/kafka-consumer-groups.sh --bootstrap-server ${IP} --list | grep -v console-consumer echo "The list of consumer groups is as follows. The console-consumer related consumer group" echo "displayed on the console has been automatically filtered for you.Copy the code

View consumer group details

"Echo" -partition :" echo "-partition :" echo" -partition :" echo "-partition :" echo" -partition :" echo "-partition :" echo" -partition: "Echo" -current-offset: indicates the OFFSET of the latest consumption of the consumer group. This value is changed during consumption. "echo" -log-end-offset: This is the current log terminal displacement for all the partitions of the topic. This is how much data we produced. "echo" -lag: The value is the difference between log-end-offset and current-offset, and represents the lag condition. The larger the value is, the serious lag is. "Echo "" /kafka/bin/kafka-consumer-groups.sh --bootstrap-server ${IP} --describe --group $group echo ""Copy the code