You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/07/30 12:37:07 UTC
(camel) branch con-mdc created (now bd27c308460)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch con-mdc
in repository https://gitbox.apache.org/repos/asf/camel.git
at bd27c308460 CAMEL-22295: camel-core - Consumer can setup MDC with route id during internal processing (for scheduled consumers)
This branch includes the following new commits:
new bd27c308460 CAMEL-22295: camel-core - Consumer can setup MDC with route id during internal processing (for scheduled consumers)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(camel) 01/01: CAMEL-22295: camel-core - Consumer can setup MDC with route id during internal processing (for scheduled consumers)
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch con-mdc
in repository https://gitbox.apache.org/repos/asf/camel.git
commit bd27c3084602cac84f830448666581791832e9c4
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Jul 30 14:35:47 2025 +0200
CAMEL-22295: camel-core - Consumer can setup MDC with route id during internal processing (for scheduled consumers)
---
.../org/apache/camel/support/ScheduledPollConsumer.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
index ae99f7392f8..8e6c9e83935 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/ScheduledPollConsumer.java
@@ -37,11 +37,13 @@ import org.apache.camel.health.HealthCheckAware;
import org.apache.camel.spi.HttpResponseAware;
import org.apache.camel.spi.PollingConsumerPollStrategy;
import org.apache.camel.spi.ScheduledPollConsumerScheduler;
+import org.apache.camel.spi.UnitOfWork;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.PropertiesHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
/**
* A useful base class for any consumer which is polling based
@@ -80,6 +82,7 @@ public abstract class ScheduledPollConsumer extends DefaultConsumer
private volatile Throwable lastError;
private volatile Map<String, Object> lastErrorDetails;
private final AtomicLong counter = new AtomicLong();
+ private boolean usedMDCLogging;
private volatile boolean firstPollDone;
private volatile boolean forceReady;
@@ -102,6 +105,10 @@ public abstract class ScheduledPollConsumer extends DefaultConsumer
public void run() {
// avoid this thread to throw exceptions because the thread pool wont re-schedule a new thread
try {
+ if (usedMDCLogging) {
+ MDC.put(UnitOfWork.MDC_ROUTE_ID, getRouteId());
+ MDC.put(UnitOfWork.MDC_CAMEL_CONTEXT_ID, getEndpoint().getCamelContext().getName());
+ }
// log starting
if (LoggingLevel.ERROR == runLoggingLevel) {
LOG.error("Scheduled task started on: {}", this.getEndpoint());
@@ -139,6 +146,11 @@ public abstract class ScheduledPollConsumer extends DefaultConsumer
LOG.error("Error occurred during running scheduled task on: {}, due: {}."
+ " This exception is ignored and the task will run again on next poll.",
this.getEndpoint(), e.getMessage(), e);
+ } finally {
+ if (usedMDCLogging) {
+ MDC.remove(UnitOfWork.MDC_ROUTE_ID);
+ MDC.remove(UnitOfWork.MDC_CAMEL_CONTEXT_ID);
+ }
}
}
@@ -639,6 +651,8 @@ public abstract class ScheduledPollConsumer extends DefaultConsumer
protected void doStart() throws Exception {
super.doStart();
+ usedMDCLogging = getEndpoint().getCamelContext().isUseMDCLogging() != null && getEndpoint().getCamelContext().isUseMDCLogging();
+
boolean newScheduler = false;
if (scheduler == null) {
DefaultScheduledPollConsumerScheduler scheduler