我想处理服务器DisconnectException并在发生服务器DisconnectException时终止应用程序
如何捕获此错误并停止应用程序?
@KafkaListener(topics = { "${kafka.status-topic}", "${kafka.start-topic}" }, containerFactory = "kafkaListenerContainerFactory")
public void listen(@Payload final String message,
@Header(KafkaHeaders.RECEIVED_TOPIC) final String topic) {
log.debug("Received '{}'-message {} from Kafka", topic, message);
LinkedList<IMessageListener> topicListeners = listeners.get(topic);
for (final IMessageListener l : topicListeners) {
// call listeners in a separate thread
executor.execute(new Runnable() {
@Override
public void run() {
l.messageReceived(topic, message);
}
});
}
}
答案 0 :(得分:0)
您可以尝试捕获异常,然后在catch块内调用System.exit(0)