[
https://issues.apache.org/jira/browse/CAMEL-16005?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Marco Collovati updated CAMEL-16005:
------------------------------------
Description:
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
was:
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
> 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
> Affects Versions: 3.7.0
> Reporter: Marco Collovati
> Priority: Major
> 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)