类型不匹配:无法从map< string,consumerrecords< string,supplier>>转换为consumerrecords< string,supplier>

klh5stk1  于 2021-06-08  发布在  Kafka
关注(0)|答案(1)|浏览(609)

当我试着运行我的 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>

arknldoa

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或更高版本)的发行版质量版本,那么您的代码应该可以编译。

相关问题