[英]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? 有没有一种简单的方法来执行此关闭步骤?
My intention was to set the UncaughtExceptionHandler
method on the KafkaStreams
object, to do the following: 我的目的是在
KafkaStreams
对象上设置UncaughtExceptionHandler
方法,以执行以下操作:
close
method on the original KafkaStreams
object KafkaStreams
对象上的close
方法关闭流 What results from that is: 结果是:
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.