2017-06-06 311 views
0

当我试图在eclipse中运行我的SupplierConsumer类时,出现这些错误。这里是我的代码:类型不匹配:无法从Map <String,ConsumerRecords <String,Supplier >>转换为ConsumerRecords <String,供应商>

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()); 
        } 
      } 
    } 
} 
  1. 类型不匹配:不能从List<String>转换为String
  2. 类型不匹配:不能转换从Map<String,ConsumerRecords<String,Supplier>>ConsumerRecords<String,Supplier>
+0

错误发生在哪里?用注释标记行或添加最小堆栈跟踪。 –

+0

1 error is coming here consumer.subscribe(Arrays.asList(topicName)); –

+0

和第二个错误在consumer.poll(100); –

回答

相关问题