我是kafka的新手我想为我们的play-scala项目实现一个kafka消息管道系统,我创建了一个插入记录的主题,我写了这样的消费者代码,
val recordBatch = new ListBuffer[CountryModel]
consumer.subscribe(Arrays.asList("session-queue"))
while (true) {
val records = consumer.poll(1000)
val iter = records.iterator()
while (iter.hasNext()) {
val record: ConsumerRecord[String, String] = iter.next()
recordBatch += Json.parse(record.value()).as[CountryModel]
}
processData(recordBatch)
// Thread.sleep(5 * 1000)
}
but after certain time the service is stopping, the processor is going to 100% after certain time machine is stopping, how can i handle this infinite loop.
在生产环境中我不能依赖这个循环吧我试着睡了一段时间,但这不是一个优雅的解决方案