You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/01/18 10:36:19 UTC
[camel] branch main updated: CAMEL-17493: ignore safe exceptions when unsubscribing
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 07187b7 CAMEL-17493: ignore safe exceptions when unsubscribing
07187b7 is described below
commit 07187b7f3d2196c24920da44df720bb078258d50
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Fri Jan 14 19:25:43 2022 +0100
CAMEL-17493: ignore safe exceptions when unsubscribing
---
.../camel/component/kafka/KafkaFetchRecords.java | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
index d51af7a..a2347fa 100644
--- a/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
+++ b/components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaFetchRecords.java
@@ -240,12 +240,27 @@ class KafkaFetchRecords implements Runnable {
}
private void safeUnsubscribe() {
+ final String printableTopic = getPrintableTopic();
+
try {
consumer.unsubscribe();
+ } catch (IllegalStateException e) {
+ LOG.warn("The consumer is likely already closed. Skipping the unsubscription from {}", printableTopic);
} catch (Exception e) {
kafkaConsumer.getExceptionHandler().handleException(
- "Error unsubscribing " + threadId + " from kafka topic " + topicName,
- e);
+ "Error unsubscribing thread " + threadId + " from kafka " + printableTopic, e);
+ }
+ }
+
+ /*
+ * This is only used for presenting log messages that take into consideration that it might be subscribed to a topic
+ * or a topic pattern.
+ */
+ private String getPrintableTopic() {
+ if (topicPattern != null) {
+ return "topic pattern" + topicPattern;
+ } else {
+ return "topic" + topicName;
}
}