camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1238387 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/MDCUnitOfWork.java test/java/org/apache/camel/processor/MDCTest.java
Date Tue, 31 Jan 2012 10:48:23 GMT
Author: davsclaus
Date: Tue Jan 31 10:48:23 2012
New Revision: 1238387

URL: http://svn.apache.org/viewvc?rev=1238387&view=rev
Log:
CAMEL-4962: Added messageId to MDC logging

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MDCTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java?rev=1238387&r1=1238386&r2=1238387&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java Tue Jan
31 10:48:23 2012
@@ -34,6 +34,7 @@ public class MDCUnitOfWork extends Defau
 
     public static final String MDC_BREADCRUMB_ID = "breadcrumbId";
     public static final String MDC_EXCHANGE_ID = "exchangeId";
+    public static final String MDC_MESSAGE_ID = "messageId";
     public static final String MDC_CORRELATION_ID = "correlationId";
     public static final String MDC_ROUTE_ID = "routeId";
     public static final String MDC_CAMEL_CONTEXT_ID = "camelContextId";
@@ -43,6 +44,7 @@ public class MDCUnitOfWork extends Defau
 
     private final String originalBreadcrumbId;
     private final String originalExchangeId;
+    private final String originalMessageId;
     private final String originalCorrelationId;
     private final String originalRouteId;
     private final String originalCamelContextId;
@@ -53,14 +55,17 @@ public class MDCUnitOfWork extends Defau
 
         // remember existing values
         this.originalExchangeId = MDC.get(MDC_EXCHANGE_ID);
+        this.originalMessageId = MDC.get(MDC_MESSAGE_ID);
         this.originalBreadcrumbId = MDC.get(MDC_BREADCRUMB_ID);
         this.originalCorrelationId = MDC.get(MDC_CORRELATION_ID);
         this.originalRouteId = MDC.get(MDC_ROUTE_ID);
         this.originalCamelContextId = MDC.get(MDC_CAMEL_CONTEXT_ID);
         this.originalTransactionKey = MDC.get(MDC_TRANSACTION_KEY);
 
-        // must add exchange id in constructor
+        // must add exchange and message id in constructor
         MDC.put(MDC_EXCHANGE_ID, exchange.getExchangeId());
+        String msgId = exchange.hasOut() ? exchange.getOut().getMessageId() : exchange.getIn().getMessageId();
+        MDC.put(MDC_MESSAGE_ID, msgId);
         // the camel context id is from exchange
         MDC.put(MDC_CAMEL_CONTEXT_ID, exchange.getContext().getName());
         // and add optional correlation id
@@ -140,6 +145,11 @@ public class MDCUnitOfWork extends Defau
         } else {
             MDC.remove(MDC_EXCHANGE_ID);
         }
+        if (this.originalMessageId != null) {
+            MDC.put(MDC_MESSAGE_ID, originalMessageId);
+        } else {
+            MDC.remove(MDC_MESSAGE_ID);
+        }
         if (this.originalCorrelationId != null) {
             MDC.put(MDC_CORRELATION_ID, originalCorrelationId);
         } else {
@@ -176,6 +186,7 @@ public class MDCUnitOfWork extends Defau
         private final AsyncCallback delegate;
         private final String breadcrumbId;
         private final String exchangeId;
+        private final String messageId;
         private final String correlationId;
         private final String routeId;
         private final String camelContextId;
@@ -183,6 +194,7 @@ public class MDCUnitOfWork extends Defau
         private MDCCallback(AsyncCallback delegate) {
             this.delegate = delegate;
             this.exchangeId = MDC.get(MDC_EXCHANGE_ID);
+            this.messageId = MDC.get(MDC_MESSAGE_ID);
             this.breadcrumbId = MDC.get(MDC_BREADCRUMB_ID);
             this.correlationId = MDC.get(MDC_CORRELATION_ID);
             this.camelContextId = MDC.get(MDC_CAMEL_CONTEXT_ID);
@@ -206,6 +218,9 @@ public class MDCUnitOfWork extends Defau
                     if (exchangeId != null) {
                         MDC.put(MDC_EXCHANGE_ID, exchangeId);
                     }
+                    if (messageId != null) {
+                        MDC.put(MDC_MESSAGE_ID, messageId);
+                    }
                     if (correlationId != null) {
                         MDC.put(MDC_CORRELATION_ID, correlationId);
                     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MDCTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MDCTest.java?rev=1238387&r1=1238386&r2=1238387&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MDCTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MDCTest.java Tue Jan 31
10:48:23 2012
@@ -60,6 +60,7 @@ public class MDCTest extends ContextTest
                             public void process(Exchange exchange) throws Exception {
                                 assertEquals("route-a", MDC.get("routeId"));
                                 assertEquals(exchange.getExchangeId(), MDC.get("exchangeId"));
+                                assertEquals(exchange.getIn().getMessageId(), MDC.get("messageId"));
                             }
                         })
                         .to("log:foo").to("direct:b");
@@ -69,6 +70,7 @@ public class MDCTest extends ContextTest
                             public void process(Exchange exchange) throws Exception {
                                 assertEquals("route-b", MDC.get("routeId"));
                                 assertEquals(exchange.getExchangeId(), MDC.get("exchangeId"));
+                                assertEquals(exchange.getIn().getMessageId(), MDC.get("messageId"));
                             }
                         })
                         .to("log:bar").to("mock:result");



Mime
View raw message