Step 5: Produce and consume data
In this step of Get Started Using Amazon MSK, you produce and consume data.
To produce and consume messages
-
Run the following command to start a console producer.
$KAFKA_ROOT/bin/kafka-console-producer.sh --broker-list $BOOTSTRAP_SERVER --producer.config $KAFKA_ROOT/config/client.properties --topic
MSKTutorialTopic
-
Enter any message that you want, and press Enter. Repeat this step two or three times. Every time you enter a line and press Enter, that line is sent to your Apache Kafka cluster as a separate message.
-
Keep the connection to the client machine open, and then open a second, separate connection to that machine in a new window. Because this is a new session, set the
KAFKA_ROOT
andBOOTSTRAP_SERVER
environment variables again. For information about how to set these environment variables, see Creating a topic on the client machine. -
Run the following command with your second connection string to the client machine to create a console consumer.
$KAFKA_ROOT/bin/kafka-console-consumer.sh --bootstrap-server $BOOTSTRAP_SERVER --consumer.config $KAFKA_ROOT/config/client.properties --topic
MSKTutorialTopic
--from-beginningYou should start seeing the messages you entered earlier when you used the console producer command.
-
Enter more messages in the producer window, and watch them appear in the consumer window.
Next Step
Step 6: Use Amazon CloudWatch to view Amazon MSK metrics