[
https://issues.apache.org/jira/browse/CAMEL-16005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17261152#comment-17261152
]
Claus Ibsen commented on CAMEL-16005:
-------------------------------------
Thanks Marco.
Yeah I looked into this, and I am adding a setGeneatedId method on IdAware so
we can use this method instead to know it was an auto assigned ID.
You are welcome to create a PR with your unit test so we have that to help test
my change.
> Route built from template with parallel processing recipient list fails to
> start because of duplicate node id.
> --------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-16005
> URL: https://issues.apache.org/jira/browse/CAMEL-16005
> Project: Camel
> Issue Type: Bug
> Components: camel-core
> Affects Versions: 3.7.0
> Reporter: Marco Collovati
> Priority: Major
> Fix For: 3.7.1, 3.8.0
>
> Attachments: TemplateRouteTest.java
>
>
> Adding multiple route instances using a route template with a recipient list
> configured for _parallel processing_, fails with a
> *FailedToStartRouteException* when starting the second route instance, due to
> duplicate id on recipientList node.
> To reproduce, define a route template as following
> {code:java}
> routeTemplate("myTemplate")
> .templateParameter("input")
> .from("direct:input")
> .recipientList(constant("mock:a,mock:b")).parallelProcessing().end()
> .to("mock:result");
> {code}
> and then add multiple routes to the context
> {code:java}
> context.addRouteFromTemplate("testRouteId1", "myTemplate", Map.of("input",
> "a"));
> context.addRouteFromTemplate("testRouteId2", "myTemplate", Map.of("input",
> "b"));{code}
> when Camel Context starts, the following exception is throw
> {noformat}
> Caused by: org.apache.camel.FailedToStartRouteException: Failed to start
> route testRouteId2 because of duplicate id detected: recipientList1. Please
> correct ids to be unique among all your routes.
> at
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:581)
> at
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:557)
> at
> org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2642)
> at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
> at
> org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2414)
> at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
> at
> org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2431){noformat}
>
> This happens with Camel 3.7, but not with 3.6. It seems to me that the
> problem may be in the new implementation of
> *DefaultExecutorServiceManager.forceId*;
> on camel 3.6 the method was defined as
> {code:java}
> protected Object forceId(Object source) {
> if (source instanceof OptionalIdentifiedDefinition) {
> NodeIdFactory factory =
> getCamelContext().adapt(ExtendedCamelContext.class).getNodeIdFactory();
> ((OptionalIdentifiedDefinition) source).idOrCreate(factory);
> }
> return source;
> }
> {code}
> in 3.7 the implementation is
> {code:java}
> protected Object forceId(Object source) {
> if (source instanceof NamedNode && source instanceof IdAware) {
> NamedNode node = (NamedNode) source;
> NodeIdFactory factory =
> getCamelContext().adapt(ExtendedCamelContext.class).getNodeIdFactory();
> if (node.getId() == null) {
> String id = factory.createId(node);
> ((IdAware) source).setId(id);
> }
> }
> return source;
> }
> {code}
> The main difference I noticed here is that using *idOrCreate* on source
> object does not set the internal *customId* flag, whereas *setId* sets the
> flag to true.
> if I have correctly understood, *RouteDefinitionHelper.validateUniqueIds*
> only takes care of custom ids when searching for duplicates, so using *setId*
> may be the culprit
> of the problem.
>
> Attached source code to reproduce the error
--
This message was sent by Atlassian Jira
(v8.3.4#803005)