Skip to content

Instantly share code, notes, and snippets.

@vik-y
Forked from diegoicosta/aliases-kafka.sh
Last active April 22, 2021 16:18
Show Gist options
  • Save vik-y/ce610293267f54aa73fdbe5bcbbb3fcd to your computer and use it in GitHub Desktop.
Save vik-y/ce610293267f54aa73fdbe5bcbbb3fcd to your computer and use it in GitHub Desktop.
Aliases useful for working with kafka
#KAFKA ALIAS TO BE USED INSIDE DOCKER
export KAFKA_HOME=/opt/kafka
export BROKER="172.17.0.1:32768"
export BOOTSTRAP="172.17.0.1:32768"
export ZK="172.17.0.1:2181"
alias k-list-topics="$KAFKA_HOME/bin/kafka-topics.sh --list --zookeeper $ZK"
alias k-create-topic="$KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $ZK --replication-factor 1 --partitions 3 --topic"
alias k-del-topic="$KAFKA_HOME/bin/kafka-topics.sh --zookeeper $ZK --delete --topic "
show_topic() {
$KAFKA_HOME/bin/kafka-console-consumer.sh \
--bootstrap-server $BOOTSTRAP \
--topic $1 --property print.key=true \
--property key.separator=, \
--from-beginning
}
consume_topic(){
$KAFKA_HOME/bin/kafka-console-consumer.sh \
--bootstrap-server $BOOTSTRAP \
--topic $1 --property print.key=true \
--property key.separator=,
}
describe_topic(){
$KAFKA_HOME/bin/kafka-topics.sh \
--zookeeper $ZK \
--topic $1 \
--describe
}
send_to_topic() {
echo "$1" | $KAFKA_HOME/bin/kafka-console-producer.sh \
--broker-list $BROKER \
--topic $2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment