Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-16005

Route built from template with parallel processing recipient list fails to start because of duplicate node id.

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.7.0
    • 3.7.1, 3.8.0
    • camel-core
    • None
    • Unknown

    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

      routeTemplate("myTemplate")
       .templateParameter("input")
       .from("direct:input")
       .recipientList(constant("mock:a,mock:b")).parallelProcessing().end()
       .to("mock:result");
      

      and then add multiple routes to the context

      context.addRouteFromTemplate("testRouteId1", "myTemplate", Map.of("input", "a"));
      context.addRouteFromTemplate("testRouteId2", "myTemplate", Map.of("input", "b"));

       when Camel Context starts, the following exception is throw

      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)

       
      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

      protected Object forceId(Object source) {
        if (source instanceof OptionalIdentifiedDefinition) { 
          NodeIdFactory factory = getCamelContext().adapt(ExtendedCamelContext.class).getNodeIdFactory();
          ((OptionalIdentifiedDefinition) source).idOrCreate(factory); 
        }
        return source;
       }
      

      in 3.7 the implementation is

       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;
       }
      

      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

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            davsclaus Claus Ibsen
            mcollovati Marco Collovati
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment