繁体   English   中英

卡夫卡消费者只给出第一条消息

[英]Kafka Consumer giving only first produced message

我是Kafka的新手。 我正在为Java使用Kafka 0.9.0.0客户端。 在使用特定主题的数据时,每次启动生产者-消费者Java项目时,都会收到相同的消息(第一次发布)。

我的要求是产生一些消息并使用它,并检查两个消息是否相同。

以下是我用于Kafka Consumer的代码:-

KafkaConsumer<String, String> newConsumer = new KafkaConsumer<String, String>(properties);
newConsumer.subscribe(Collections.singletonList(props.getProperty("monitoring.topic")));

String consumerRecord = "";
ConsumerRecords<String, String> consumerRecords = newConsumer.poll(120000);

for (ConsumerRecord<String, String> record : consumerRecords) {
    logger.info("Found message  for  {} {} {}", adapter, record.key(), record.value());
    System.out.println("consumerMessage : " + record.value());
    JSONObject jsonConsumerMessage = (JSONObject) (parser.parse(record.value()));

    Long offset = record.offset();
    System.out.println("Offset of this record is " + offset);
    String UUIDProducer = message.get("UUID").toString();

    String UUIDConsumer = jsonConsumerMessage.get("UUID").toString();
    System.out.println("UUIDProducer :  " + UUIDProducer);
    System.out.println("UUIDConsumer :  " + UUIDConsumer);
    if (UUIDProducer.equals(UUIDConsumer)) {
        return true;
    } else
        return false;
}

注意:-我能够通过命令行使用最新消息。

有人可以指导我吗?

我在for循环中返回true和false值是我的愚蠢错误。 一旦主题发出第一条消息,就会引起循环。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM