This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit f16cae2deb4c26a27cf5f62cfae2fe4ed4746d89 Author: Pasquale Congiusti <[email protected]> AuthorDate: Fri Dec 19 11:21:50 2025 +0100 chore(components): simplify mdc CompletableFuture method --- .../camel/mdc/MDCProcessorsInterceptStrategy.java | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/components/camel-mdc/src/main/java/org/apache/camel/mdc/MDCProcessorsInterceptStrategy.java b/components/camel-mdc/src/main/java/org/apache/camel/mdc/MDCProcessorsInterceptStrategy.java index 3e079e71fb7b..6e81b0a0e5c0 100644 --- a/components/camel-mdc/src/main/java/org/apache/camel/mdc/MDCProcessorsInterceptStrategy.java +++ b/components/camel-mdc/src/main/java/org/apache/camel/mdc/MDCProcessorsInterceptStrategy.java @@ -26,6 +26,7 @@ import org.apache.camel.Exchange; import org.apache.camel.NamedNode; import org.apache.camel.Processor; import org.apache.camel.spi.InterceptStrategy; +import org.apache.camel.support.AsyncCallbackToCompletableFutureAdapter; import org.apache.camel.support.AsyncProcessorConverterHelper; import org.slf4j.MDC; @@ -93,23 +94,12 @@ public class MDCProcessorsInterceptStrategy implements InterceptStrategy { @Override public CompletableFuture<Exchange> processAsync(Exchange exchange) { - CompletableFuture<Exchange> future = new CompletableFuture<>(); - Map<String, String> previousContext = MDC.getCopyOfContextMap(); - mdcService.setMDC(exchange); - asyncProcessor.process(exchange, doneSync -> { - if (exchange.getException() != null) { - future.completeExceptionally(exchange.getException()); - } else { - future.complete(exchange); - } - if (previousContext != null) { - MDC.setContextMap(previousContext); - } else { - MDC.clear(); - } - }); - return future; + AsyncCallbackToCompletableFutureAdapter<Exchange> callback + = new AsyncCallbackToCompletableFutureAdapter<>(exchange); + process(exchange, callback); + return callback.getFuture(); } + }; }
