The only dependency for running these examples is Docker Compose.
Once Docker Compose is installed, you can start the local Kafka cluster using the following command:
$ docker-compose -f kafka-single-broker.yml up --dNow, log into the broker, since this is where we will be running our commands.
$ docker-compose exec kafka bashOnce you're logged into the broker, run the following command to create a topic called foobar:
$ kafka-topics \ --bootstrap-server localhost:9092 \ --create \ --partitions 1 \ --replication-factor 1 \ --topic foobar - Create topics
input-topic-1,input-topic-2,output-topic-1,output-topic-2using above command
Once you've created the foobar topic, you can describe it using the following command:
$ kafka-topics \ --bootstrap-server localhost:9092 \ --describe \ --topic foobarThe following command will allow you to produce data to the foobar topic that we created earlier. Run the following to be dropped into a prompt:
$ kafka-console-producer \ --bootstrap-server localhost:9092 \ --property key.separator=, \ --property parse.key=true \ --topic foobarOnce you are in the prompt, produce a few records. Keys and values are separated by ,, and you'll need to hit <Enter> on your keyboard after each row.
1,mitch 2,elyse 3,isabelle 4,sammyWhen you are finished, press Control-C on your keyboard to exit the prompt.
Run the following command to consume the data we just produced to the foobar topic in the section above.
$ kafka-console-consumer \ --bootstrap-server localhost:9092 \ --topic foobar \ --from-beginningYou should see the following output:
mitch isabelle sammy elysegradlew bootRun Once you are done, log out of the broker by typing exit and run the following command to tear down the local Kafka cluster:
docker-compose down