Skip to content

Instantly share code, notes, and snippets.

@navicore
Last active May 24, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navicore/370c1066d36aeb7b47f80f5b96a24399 to your computer and use it in GitHub Desktop.
Save navicore/370c1066d36aeb7b47f80f5b96a24399 to your computer and use it in GitHub Desktop.
run cassandra and kafka in docker for local dev

kafka

docker run -d --name my-kafka -p 2181:2181 -p 9092:9092 --env "ADVERTISED_HOST=`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`" --env "ADVERTISED_PORT=9092" spotify/kafka

to use the broker, cd into the bin dir of a kafka installation

create a topic:

./kafka-topics.sh --create --topic topic1 --zookeeper=`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`:2181 --partitions 2 --replication-factor 1

create a consumer:

./kafka-console-consumer.sh --topic topic1 --bootstrap-server=`ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`:9092

write a file into a topic:

./kafka-console-producer.sh --broker-list `ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'`:9092 --topic topic1 < ~/MY_FILE_I_WISH_WAS_IN_KAFKA.json

cassandra

docker run -p 9042:9042 --name my-cassandra -d cassandra:3.11

interact with db via cli

docker run -it --link my-cassandra:cassandra --rm cassandra:3.11 sh -c 'exec cqlsh "$CASSANDRA_PORT_9042_TCP_ADDR"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment