当我在eclipse中尝试运行SupplierConsumer
类时,我遇到了这些错误。这是我的代码:
public class SupplierConsumer{
public static void main(String[] args) throws Exception{
String topicName = "SupplierTopic";
String groupName = "SupplierTopicGroup";
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092,localhost:9093");
props.put("group.id", groupName);
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "SupplierDeserializer");
KafkaConsumer<String, Supplier> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Arrays.asList(topicName));
while (true){
ConsumerRecords<String, Supplier> records = consumer.poll(100);
for (ConsumerRecord<String, Supplier> record : records){
System.out.println("Supplier id= " + String.valueOf(record.value().getID()) + " Supplier Name = " + record.value().getName() + " Supplier Start Date = " + record.value().getStartDate().toString());
}
}
}
}
List<String>
转换为String
,Map<String,ConsumerRecords<String,Supplier>>
转换为ConsumerRecords<String,Supplier>
答案 0 :(得分:0)
我认为你无意中在你的类路径中包含了一些kafka-clients库的预发布版本。我在v0.8.2-beta中找到了与你的编译错误匹配的签名:
如果您确保使用kafka-clients jar的发行版质量版本(v0.9或更高版本),则应编译代码。