Step 5: Produce and consume data - Amazon Managed Streaming for Apache Kafka
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Step 5: Produce and consume data

In this step of Getting Started Using Amazon MSK, you produce and consume data.

To produce and consume messages
  1. Run the following command to start a console producer. Replace BootstrapServerString with the plaintext connection string that you obtained in Create a topic. For instructions on how to retrieve this connection string, see Getting the bootstrap brokers for an Amazon MSK cluster.

    <path-to-your-kafka-installation>/bin/ --broker-list BootstrapServerString --producer.config --topic MSKTutorialTopic
  2. 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.

  3. Keep the connection to the client machine open, and then open a second, separate connection to that machine in a new window.

  4. In the following command, replace BootstrapServerString with the plaintext connection string that you saved earlier. Then, to create a console consumer, run the following command with your second connection to the client machine.

    <path-to-your-kafka-installation>/bin/ --bootstrap-server BootstrapServerString --consumer.config --topic MSKTutorialTopic --from-beginning

    You start seeing the messages you entered earlier when you used the console producer command.

  5. 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