Created
January 14, 2021 01:02
-
-
Save futeng/9cbe5653a461a7686df1af623e2635f2 to your computer and use it in GitHub Desktop.
[basic kafka status test] test kafka when doubt the status #kafka #test #status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Copyright futeng@tydic.com | |
# Jul 24, 2020 | |
# | |
# NAME: testKafka.sh | |
# FUNC: 测试 Kafka 安装的正确性 | |
# POSI: 任意目录 | |
# EXEC: sh basic_kafka_test.sh | |
bin_path="/usr/hdp/current/kafka-broker/bin" | |
zk_addr="bigdata102195:2181" | |
listeners="bigdata102197:6667" | |
broker_list=$listeners | |
alias kafka-topics="$bin_path/kafka-topics.sh --zookeeper $zk_addr" | |
alias kafka-console-producer="$bin_path/kafka-console-producer.sh --broker-list $broker_list" | |
alias kafka-console-consumer="$bin_path/kafka-console-consumer.sh --bootstrap-server $broker_list" | |
echo "######## START TEST KAFKA #######" | |
echo "==>1. list topics" | |
kafka-topics --list | |
echo "==>2. create topic tydic-test with 3 patitions and with 3 replication factor" | |
kafka-topics --create --replication-factor 3 --partitions 3 --topic tydic-test | |
echo "==>3. produce some data" | |
kafka-console-producer --topic tydic-test < /etc/hosts | |
echo "==> 4. comsume this topic in one second" | |
kafka-console-consumer --topic tydic-test --from-beginning --timeout-ms 100 | |
echo "==> NOTICE:Shutdown consume in one second, and it's OK to get the message: ERROR Error processing message." | |
echo "==> 5. delete topic" | |
kafka-topics --delete --topic tydic-test | |
echo | |
status=$? | |
echo "The status was " $status | |
if [ $status == 0 ]; then | |
echo "==> test success<==" | |
else | |
echo "==> test failure <==" | |
fi | |
echo "######## STOP TEST KAFKA #######" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment