在Spring Boot中使用kafkastreams,我有一个在标点符中捕获的异常,如下所示:
try {
return record.toBuilder().apiResponse(userFeed.addActivity(activity).join()).success(Boolean.TRUE).build();
} catch (StreamException e) {
e.printStackTrace();
return record.toBuilder().success(Boolean.FALSE).build();
}
但是,这个异常会导致流应用程序关闭:
org.apache.kafka.streams.errors.StreamsException: stream-thread [notification-service-StreamThread-1] task [0_2] Exception caught while punctuating processor 'KSTREAM-PROCESSOR-0000000001'
2023-01-20T15:39:33.269Z ERROR 1 --- [-StreamThread-1] org.apache.kafka.streams.KafkaStreams : stream-client [notification-service] Encountered the following exception during processing and the registered exception handler opted to SHUTDOWN_CLIENT. The streams client is going to shut down now.
如何更改已注册的异常处理程序以不关闭客户端?所有的文档都在讨论未捕获的异常处理程序,但我正在捕获这个异常。我甚至不知道注册处理程序是什么。
事实证明,由于线程怪异,实际上没有正确捕获异常,因此设置未捕获的异常处理程序解决了这个问题。