You need to make sure both zookeeper and Kafka server are running before executing the commands. Also, please create the Kafka topic before test the producer and consumer.
You can use built-in producer and consumer to test the message flow in Kafka topics.
Please follow the below steps to test it.