当我试着运行我的 SupplierConsumer
在eclipse中初始化。这是我的密码:
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>
1条答案
按热度按时间arknldoa1#
我认为您无意中在类路径中包含了一些Kafka客户机库的预发行版本。我在v0.8.2-beta中找到了与编译错误匹配的签名:
http://supergsego.com/apache/kafka/0.8.2-beta/java-doc/org/apache/kafka/clients/consumer/kafkaconsumer.html
如果您确保使用kafka clients jar(v0.9或更高版本)的发行版质量版本,那么您的代码应该可以编译。