Created
February 20, 2016 06:20
-
-
Save garukun/2136424ad962d28067b5 to your computer and use it in GitHub Desktop.
Bash Kafka Script
This file contains hidden or 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
#!/bin/bash | |
# kftopic performs several Kafka utility commands on a particular running Kafka | |
# container. See usage. | |
function kftopic { | |
case "_$1" in | |
_create) | |
docker exec $2 /bin/bash -c "\$KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic $3" ;; | |
_describe) | |
docker exec $2 /bin/bash -c "\$KAFKA_HOME/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic $3" ;; | |
_list) | |
docker exec $2 /bin/bash -c "\$KAFKA_HOME/bin/kafka-topics.sh --list --zookeeper localhost:2181" ;; | |
_consume) | |
docker exec -it $2 /bin/bash -c "\$KAFKA_HOME/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic $3 --from-beginning" ;; | |
_produce) | |
docker exec -it $2 /bin/bash -c "\$KAFKA_HOME/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic $3" ;; | |
_) | |
echo "kafka_topic [create|describe|list|consume|produce] [container_name|image] [topic]" ;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment