I am running this kafka producer example mentioned in its site
The code:
public class TestProducer {
public static void main(String[] args) {
ForHDP kafka use broker port: 6667
For Standalone kafka use broker port: 9092
The error was because of the port no which we were using (HDP uses 6667 but we were using 9092)
bin/kafka-console-producer.sh --broker-list broker-ip:9092 --topic test //not working
bin/kafka-console-producer.sh --broker-list broker-ip:6667 --topic test //working
link: Kafka console producer Error in Hortonworks HDP 2.3 Sandbox