执行报错
来源:4-9 -Kafka Producer Java API编程

weixin_慕哥1181079
2019-11-18
执行KafkaClientApp 类时报错
错误定位的37,21是这一行:
producer.send(new KeyedMessage<Integer, String>(topic, message));
写回答
2回答
-
你的produce代码贴下看看
012019-11-18 -
weixin_慕哥1181079
提问者
2019-11-18
package com.imooc.spark.kafka; import kafka.javaapi.producer.Producer; import kafka.producer.KeyedMessage; import kafka.producer.ProducerConfig; import java.util.Properties; /** * Kafka 生产者 */ public class KafkaProducer extends Thread { private String topic; private Producer<Integer, String> producer; public KafkaProducer(String topic) { this.topic = topic; Properties properties = new Properties(); properties.put("metadata.broker.list",KafkaProperties.BROKER_LIST); properties.put("serializer.class","kafka.serializer.StringEncoder"); properties.put("request.required.acks","1"); producer = new Producer<Integer, String>(new ProducerConfig(properties)); } @Override public void run() { int messageNo = 1; while(true) { String message = "message_" + messageNo; producer.send(new KeyedMessage<Integer, String>(topic, message)); System.out.println("Sent: " + message); messageNo ++ ; try{ Thread.sleep(2000); } catch (Exception e){ e.printStackTrace(); } } } }
072019-11-19
相似问题