CAMEL-8755: No Message History on deadLetterChannel
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f40a200c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f40a200c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f40a200c Branch: refs/heads/master Commit: f40a200ca582ea76691871512227fe4489cabe5e Parents: 710670e Author: Claus Ibsen <[email protected]> Authored: Sun May 10 10:52:01 2015 +0200 Committer: Claus Ibsen <[email protected]> Committed: Sun May 10 10:52:01 2015 +0200 ---------------------------------------------------------------------- .../camel/builder/DeadLetterChannelBuilder.java | 5 ++- .../camel/processor/RedeliveryErrorHandler.java | 11 +++-- ...erChannelLogExhaustedMessageHistoryTest.java | 46 +++++++++++++++++++ ...orHandlerLogExhaustedMessageHistoryTest.java | 47 ++++++++++++++++++++ 4 files changed, 105 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f40a200c/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java index d7a9d3b..f598d51 100644 --- a/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java +++ b/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java @@ -98,7 +98,10 @@ public class DeadLetterChannelBuilder extends DefaultErrorHandlerBuilder { @Override protected RedeliveryPolicy createRedeliveryPolicy() { - return new RedeliveryPolicy(); + RedeliveryPolicy answer = new RedeliveryPolicy(); + // do not log exhausted message history by default for DLC + answer.setLogExhaustedMessageHistory(false); + return answer; } protected CamelLogger createLogger() { http://git-wip-us.apache.org/repos/asf/camel/blob/f40a200c/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java index 062ad6a..e4cf1b5 100644 --- a/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java +++ b/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java @@ -41,6 +41,7 @@ import org.apache.camel.util.AsyncProcessorConverterHelper; import org.apache.camel.util.AsyncProcessorHelper; import org.apache.camel.util.CamelContextHelper; import org.apache.camel.util.CamelLogger; +import org.apache.camel.util.EndpointHelper; import org.apache.camel.util.EventHelper; import org.apache.camel.util.ExchangeHelper; import org.apache.camel.util.MessageHelper; @@ -952,7 +953,11 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme String msg = "Failed delivery for " + ExchangeHelper.logIds(exchange); msg = msg + ". Exhausted after delivery attempt: " + data.redeliveryCounter + " caught: " + caught; if (processor != null) { - msg = msg + ". Processed by failure processor: " + processor; + if (isDeadLetterChannel && deadLetterUri != null) { + msg = msg + ". Handled by DeadLetterChannel: [" + URISupport.sanitizeUri(deadLetterUri) + "]"; + } else { + msg = msg + ". Processed by failure processor: " + processor; + } } // log that we failed delivery as we are exhausted @@ -1052,8 +1057,8 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport impleme } // if we should not rollback, then check whether logging is enabled - if (!newException && handled && !data.currentRedeliveryPolicy.isLogHandled()) { - // do not log handled + if (!newException && handled && (!data.currentRedeliveryPolicy.isLogHandled() && !data.currentRedeliveryPolicy.isLogExhaustedMessageHistory())) { + // do not log handled (but log exhausted message history can overrule log handled) return; } http://git-wip-us.apache.org/repos/asf/camel/blob/f40a200c/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.java b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.java new file mode 100644 index 0000000..f691b25 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelLogExhaustedMessageHistoryTest.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.processor; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; + +public class DeadLetterChannelLogExhaustedMessageHistoryTest extends ContextTestSupport { + + public void testLogExhaustedMessageHistory() throws Exception { + getMockEndpoint("mock:dead").expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // no delay to speedup test + errorHandler(deadLetterChannel("mock:dead").redeliveryDelay(0).maximumRedeliveries(3).logExhaustedMessageHistory(true)); + + from("direct:start") + .log("Incoming ${body}") + .throwException(new IllegalArgumentException("Forced")); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f40a200c/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java b/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java new file mode 100644 index 0000000..aec7b37 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/processor/DefaultErrorHandlerLogExhaustedMessageHistoryTest.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.processor; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; + +public class DefaultErrorHandlerLogExhaustedMessageHistoryTest extends ContextTestSupport { + + public void testLogExhaustedMessageHistory() throws Exception { + try { + template.sendBody("direct:start", "Hello World"); + fail("Should fail"); + } catch (Exception e) { + // ignore + } + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // no delay to speedup test + errorHandler(defaultErrorHandler().redeliveryDelay(0).maximumRedeliveries(3).logExhaustedMessageHistory(true)); + + from("direct:start") + .log("Incoming ${body}") + .throwException(new IllegalArgumentException("Forced")); + } + }; + } +}
