简体   繁体   English

停止Kafka Streams应用

[英]Stop a Kafka Streams app

Is it possible to have a Kafka Streams app that runs through all the data in a topic and then exits? 是否可以使用Kafka Streams应用程序运行主题中的所有数据然后退出?

Example I'm producing data into topics based on date. 示例我根据日期生成主题数据。 The consumer gets kicked off by cron, runs through all the available data and then .. does what? 消费者被cron开除,运行所有可用数据,然后......做什么? I don't want it to sit and wait for more data. 我不希望它等待更多数据。 Just assume it's all there and then exit gracefully. 只是假设它就在那里,然后优雅地退出。

Possible? 可能?

In Kafka Streams (as for other stream processing solutions), the is no "end of data" because it is stream processing in the first place -- and not batch processing. 在Kafka Streams中(和其他流处理解决方案一样),它不是“数据结束”,因为它首先是流处理 - 而不是批处理。

Nevertheless, you could watch the "lag" of your Kafka Streams application and shut it down if there is not lag (lag, is the number of not yet consumed messages). 不过,您可以观察Kafka Streams应用程序的“滞后”,如果没有滞后(滞后,是尚未消耗的消息数),请将其关闭。

For example, you can use bin/kafka-consumer-groups.sh to check the lag of your Streams application (the application ID is used as consumer group ID). 例如,您可以使用bin/kafka-consumer-groups.sh来检查Streams应用程序的延迟(应用程序ID用作使用者组ID)。 If you want to embed this in your Streams applications, you can use kafka.admin.AdminClient to get consumer group information. 如果要将其嵌入Streams应用程序中,可以使用kafka.admin.AdminClient获取使用者组信息。

You can create a consumer and then once it stops pulling up data, you can have call consumer.close() . 您可以创建一个consumer ,然后一旦它停止提取数据,您就可以调用consumer.close() Or if you want to poll again in the future just call consumer.pause() and call .resume later. 或者,如果您希望将来再次轮询,只需调用consumer.pause()并稍后调用.resume

One way to do this is within the consumer poll block. 执行此操作的一种方法是在消费者投票块中。 Such as

data = consumer.poll()
if (!data.next()) {
   consumer.close()
}

Keep in mind that poll returns ConsumerRecord<K,V> and conforms to the Iterable interface. 请记住, poll返回ConsumerRecord<K,V>并符合Iterable接口。

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

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