This is an automated email from the ASF dual-hosted git repository.
Croway 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 53140a139f5c CAMEL-25819: camel-core - Aggregate EIP recovers
exchanges when the KeyValueRepository is auto-discovered
53140a139f5c is described below
commit 53140a139f5cdd0e1e7c6b5ab7b58886e2a7d34d
Author: croway <[email protected]>
AuthorDate: Mon Oct 19 13:44:25 2026 +0200
CAMEL-25819: camel-core - Aggregate EIP recovers exchanges when the
KeyValueRepository is auto-discovered
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../processor/aggregate/AggregateProcessor.java | 2 +-
...utoDiscoveredKeyValueRepositoryRecoverTest.java | 79 ++++++++++++++++++++++
2 files changed, 80 insertions(+), 1 deletion(-)
diff --git
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
index 94228e2714b8..cb007e4f7ee1 100644
---
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
+++
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/AggregateProcessor.java
@@ -1905,7 +1905,7 @@ public class AggregateProcessor extends
BaseProcessorSupport
// Auto-discover a KeyValueRepository from the registry and wrap it
KeyValueRepository kvRepo =
camelContext.getRegistry().findSingleByType(KeyValueRepository.class);
if (kvRepo != null) {
- aggregationRepository = new
KeyValueAggregationRepository(kvRepo);
+ setAggregationRepository(new
KeyValueAggregationRepository(kvRepo));
LOG.info("Auto-discovered KeyValueRepository from registry,
wrapping as AggregationRepository");
} else {
aggregationRepository = new
MemoryAggregationRepository(optimisticLocking);
diff --git
a/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateAutoDiscoveredKeyValueRepositoryRecoverTest.java
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateAutoDiscoveredKeyValueRepositoryRecoverTest.java
new file mode 100644
index 000000000000..43ac4ef74945
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/processor/aggregator/AggregateAutoDiscoveredKeyValueRepositoryRecoverTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.aggregator;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.BodyInAggregatingStrategy;
+import org.apache.camel.spi.Registry;
+import org.apache.camel.support.MemoryKeyValueRepository;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A {@code KeyValueRepository} auto-discovered from the registry must support
recovery like an explicitly configured
+ * {@code KeyValueAggregationRepository}.
+ */
+public class AggregateAutoDiscoveredKeyValueRepositoryRecoverTest extends
ContextTestSupport {
+
+ private final MemoryKeyValueRepository kvRepo = new
MemoryKeyValueRepository();
+
+ @Override
+ protected Registry createCamelRegistry() throws Exception {
+ Registry registry = super.createCamelRegistry();
+ registry.bind("kvRepo", kvRepo);
+ return registry;
+ }
+
+ @Test
+ public void testRecoverWithAutoDiscoveredRepository() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("A+B", "A+B");
+ mock.message(1).header(Exchange.REDELIVERED).isEqualTo(true);
+ // the first attempt fails, so the aggregated exchange is recovered
+ mock.whenExchangeReceived(1, exchange -> {
+ throw new IllegalArgumentException("Forced");
+ });
+
+ template.sendBodyAndHeader("direct:start", "A", "id", 1);
+ template.sendBodyAndHeader("direct:start", "B", "id", 1);
+
+ assertMockEndpointsSatisfied();
+ // the recovered exchange is confirmed and removed from the repository
+ await().atMost(5, TimeUnit.SECONDS).untilAsserted(() ->
assertTrue(kvRepo.keys().isEmpty()));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ // no aggregationRepository: the KeyValueRepository is
auto-discovered from the registry
+ from("direct:start")
+ .aggregate(header("id"), new
BodyInAggregatingStrategy())
+ .completionSize(2)
+ .to("mock:result");
+ }
+ };
+ }
+}