简体   繁体   English

Kafka Streams:错误退出的正确方法

[英]Kafka Streams: Proper way to exit on error

I've been successful in getting a streams app to consume, transform and produce data, but I've noticed that periodically, the streams processor will transition to a state of ERROR and the process will sit there without exiting. 我已经成功地获得了一个使用,转换和生成数据的流应用程序,但我注意到,流处理器会定期转换到ERROR状态,并且该进程将在不退出的情况下停留在那里。

Showing me logs like: 显示我的日志:

All stream threads have died. The instance will be in error state and should be closed.

Is there a way to tell the Streams app to exit once its reached the ERROR state? 有没有办法告诉Streams应用程序一旦达到ERROR状态就退出? Maybe a monitor thread of sorts? 也许是各种监视器线程?

I see references in the comments of the Kafka Streams code to the user needing to close the application once its reached this state, however, I haven't been able to find mention of this task in the documentation. 我看到Kafka Streams代码的注释中的引用给需要在应用程序达到此状态时关闭应用程序的用户,但是,我无法在文档中找到提及此任务的内容。

Is there a simple way to do this shutdown step? 有没有一种简单的方法来执行此关闭步骤?


probably incorrect way to potentially close on errors 可能是错误的方式可能关闭错误

My intention was to set the UncaughtExceptionHandler method on the KafkaStreams object, to do the following: 我的目的是在KafkaStreams对象上设置UncaughtExceptionHandler方法,以执行以下操作:

  • log the error 记录错误
  • shutdown the stream using the close method on the original KafkaStreams object 使用原始KafkaStreams对象上的close方法关闭流

What results from that is: 结果是:

  • message for the exception is logged 记录异常消息
  • INFO org.apache.kafka.streams.KafkaStreams ... State transition from ERROR to PENDING_SHUTDOWN
  • INFO org.apache.kafka.streams.processor.internals.StreamThread ... Informed to shut down

And then, unfortunately the process seems to hang without exiting. 然后,不幸的是,这个过程似乎没有退出。

FWIW I feel like this is probably a misuse of the setUncaughtExceptionHandler FWIW我觉得这可能是对setUncaughtExceptionHandler的误用

Using an UncaughtExceptionHandler is correct. 使用UncaughtExceptionHandler是正确的。 However, if you call KafkaStreams#close() within the handler call-back you can run into a deadlock. 但是,如果在处理程序回调中调用KafkaStreams#close() ,则可能会遇到死锁。 Thus, you should either only set a flag, and call #close() outside of the callback, or you use close() with a timeout. 因此,您应该只设置一个标志,并在回调之外调用#close() ,或者使用close()和超时。 If the timeout expires, a shutdown is forced. 如果超时到期,则强制关闭。

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

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