[
https://issues.apache.org/jira/browse/CAMEL-16005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17261073#comment-17261073
]
Marco Collovati commented on CAMEL-16005:
-----------------------------------------
I would be glad to create a PR, but I need some help.
*IdAware* interface does not expose a *idOrCreate* method, so I can see one of
this options:
* revert to the former *forceId* implementation
* add *idOrCreate* method to the *IdAware* interface
* introduce a new interface for *idOrCreate* method and handle it in *forceId*
togheter with *IdAware*
* simply add an additional instance check for *OptionalIdentifiedDefinition* to
actual *forceId* method, and invoke *idOrCreate* or *setId* accordingly.
I don't like very much option one and two. I think the last option will be the
one with less impact on existing code, but it couples the fix to a specific
class (*OptionalIdentifiedDefinition*); the third one may be a better fit and
may leave doors open to fix similar cases on other type of *source* objects,
but requires a bit more work.
[~davsclaus] , maybe you have a better solution in mind; can you give me some
advice?
> 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)