Apache Kafka example error: Failed to send message after 3 tries

后端 未结 8 1586
南旧
南旧 2021-02-19 08:39

I am running this kafka producer example mentioned in its site

The code:

public class TestProducer {

    public static void main(String[] args) {
               


        
8条回答
  •  遇见更好的自我
    2021-02-19 09:34

    I came across this error in Hortonworks HDP 2.2 where default port is set to 6667. If your kafka server is running on HDP sandbox the resolution is to set metadata.broker.list as 10.0.2.15:6667 Please follow this code.

                Properties props = new Properties();
                props.put("metadata.broker.list", "10.0.2.15:6667");
                props.put("serializer.class", "kafka.serializer.StringEncoder");
                //props.put("producer.type","async");
                props.put("request.required.acks", "1");
                ProducerConfig config = new ProducerConfig(props);
    
                Producer producer = new Producer(config);
                try{        
                producer.send(new KeyedMessage("zerg.hydra", jsonPayload));
    
                producer.close();
            }catch(Exception e){
                e.printStackTrace();
            }
    

提交回复
热议问题