This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 ffabaa06703d CAMEL-24749: camel-core - failover load balancer honours
inheritErrorHandler=false again
ffabaa06703d is described below
commit ffabaa06703d9cbd9d38179e07e9bc7a8507ea01
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Sep 15 11:50:10 2026 +0200
CAMEL-24749: camel-core - failover load balancer honours
inheritErrorHandler=false again
Since CAMEL-21630 (4.10.0) the inheritErrorHandler option of the failover
load balancer was stored on FailoverLoadBalancerDefinition but never read:
LoadBalanceReifier still consulted the now camel-jta-only flag on the
LoadBalanceDefinition when wrapping the children, so failover(-1, false,
true)
and <failoverLoadBalancer inheritErrorHandler="false"/> behaved as true and
the error handler exhausted its redeliveries on the failing endpoint before
the load balancer failed over.
LoadBalanceReifier now wraps the children with the failover definition's
inheritErrorHandler, while the load balancer itself keeps inheriting so the
route error handler can react once the failover is exhausted (pre-4.10
behaviour). New FailOverLoadBalanceInheritErrorHandlerTest covers both
settings.
Closes #26450
Co-authored-by: Claude <[email protected]>
---
.../apache/camel/reifier/LoadBalanceReifier.java | 22 +++---
...FailOverLoadBalanceInheritErrorHandlerTest.java | 81 ++++++++++++++++++++++
2 files changed, 94 insertions(+), 9 deletions(-)
diff --git
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LoadBalanceReifier.java
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LoadBalanceReifier.java
index d222a75c4fe5..5883256fa328 100644
---
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LoadBalanceReifier.java
+++
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LoadBalanceReifier.java
@@ -47,6 +47,18 @@ public class LoadBalanceReifier extends
ProcessorReifier<LoadBalanceDefinition>
"To many outputs configured on " +
definition.getLoadBalancerType() + ": " + size + " > " + max);
}
+ Boolean inherit = parseBoolean(definition.getInheritErrorHandler());
+ Boolean childInherit = inherit;
+ if (definition.getLoadBalancerType() instanceof
FailoverLoadBalancerDefinition failover) {
+ // special for failover load balancer where you can configure it to
+ // not inherit error handler for its children (so it fails over
+ // immediately on an error instead of waiting for the error handler
+ // to exhaust its redeliveries), but the load balancer itself
should
+ // inherit so Camels error handler can react afterwards
+ childInherit = parseBoolean(failover.getInheritErrorHandler());
+ inherit = true;
+ }
+
for (ProcessorDefinition<?> processorType : definition.getOutputs()) {
// output must not be another load balancer
// check for instanceof as the code below as there is
@@ -58,18 +70,10 @@ public class LoadBalanceReifier extends
ProcessorReifier<LoadBalanceDefinition>
+ processorType);
}
Processor processor = createProcessor(processorType);
- Channel channel = wrapChannel(processor, processorType);
+ Channel channel = wrapChannel(processor, processorType,
childInherit);
loadBalancer.addProcessor(channel);
}
- Boolean inherit = parseBoolean(definition.getInheritErrorHandler());
- if (definition.getLoadBalancerType() instanceof
FailoverLoadBalancerDefinition) {
- // special for failover load balancer where you can configure it to
- // not inherit error handler for its children
- // but the load balancer itself should inherit so Camels error
- // handler can react afterwards
- inherit = true;
- }
return wrapChannel(loadBalancer, definition, inherit);
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceInheritErrorHandlerTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceInheritErrorHandlerTest.java
new file mode 100644
index 000000000000..b11bb80943ad
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceInheritErrorHandlerTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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;
+import org.junit.jupiter.api.Test;
+
+/**
+ * The inheritErrorHandler option of the failover load balancer decides
whether Camel error handler does its
+ * redeliveries on a failing endpoint before the load balancer fails over, or
the load balancer fails over immediately
+ * (CAMEL-24749).
+ */
+public class FailOverLoadBalanceInheritErrorHandlerTest extends
ContextTestSupport {
+
+ @Test
+ public void testNotInheritErrorHandlerFailsOverImmediately() throws
Exception {
+ // fails over on the first error so the bad endpoint is only called
once
+ getMockEndpoint("mock:bad").whenAnyExchangeReceived(e -> {
+ throw new IllegalStateException("Forced");
+ });
+ getMockEndpoint("mock:bad").expectedMessageCount(1);
+ getMockEndpoint("mock:good").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:noInherit", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testInheritErrorHandlerRedeliversFirst() throws Exception {
+ // the error handler does its 2 redeliveries on the bad endpoint
before the load balancer fails over
+ getMockEndpoint("mock:bad").whenAnyExchangeReceived(e -> {
+ throw new IllegalStateException("Forced");
+ });
+ getMockEndpoint("mock:bad").expectedMessageCount(3);
+ getMockEndpoint("mock:good").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:inherit", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+
errorHandler(defaultErrorHandler().maximumRedeliveries(2).redeliveryDelay(0));
+
+ from("direct:noInherit")
+ .loadBalance().failover(-1, false, true)
+ .to("mock:bad").to("mock:good")
+ .end()
+ .to("mock:result");
+
+ from("direct:inherit")
+ .loadBalance().failover(-1, true, true)
+ .to("mock:bad").to("mock:good")
+ .end()
+ .to("mock:result");
+ }
+ };
+ }
+
+}