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

OnCompletion behaves strange in combination with direct subroutes

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.23.2, 2.24.0
    • Fix Version/s: 3.x
    • Component/s: came-core
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      There is a strange behaviour in .onCompletion().modeBeforeConsumer() when used in combination with direct sub-routes.

      The route behaves differently depending on where onCompletion is declared. When declared in the top of the route it will execute several times. Once for every route, including the subroutes.

      I have made a small spring-boot sample app where I try to demonstrate this behaviour.
      https://github.com/jakobthun/camel-oncompletion-bug

      This route:

          public static final String ORIGINAL_ROUTE_NAME  = "PossibleBug-original-route";
          public static final String SUBROUTE_NAME        = "PossibleBug-subroute";
          public static final String DIRECT_ENDPOINT      = "direct:possiblebug";
      
          @Override
          public void configure() throws Exception {
      
              from("timer:expected?period=10000&delay=5000")
                      .routeId(ORIGINAL_ROUTE_NAME)
                      .onCompletion().modeBeforeConsumer()
                          .log("This should be done once, when the original route is completed i.e. after log 3. But when onCompletion is defined in top of route AND it is in modeBeforeConsumer() it will also be applied to when the direct-route is completed. So it will be executed twice.")
                      .end()
                      .log("1")
                      .to(DIRECT_ENDPOINT)
                      .log("3");
      
              from(DIRECT_ENDPOINT)
                      .routeId(SUBROUTE_NAME)
                      .log("2");
      
          }
      

       Generates the following log:

      2019-05-21 14:50:24.545  INFO 138880 --- [imer://expected] PossibleBug-original-route               : 1
      2019-05-21 14:50:24.545  INFO 138880 --- [imer://expected] PossibleBug-subroute                     : 2
      2019-05-21 14:50:24.545  INFO 138880 --- [imer://expected] PossibleBug-original-route               : This should be done once, when the original route is completed i.e. after log 3. When onCompletion is defined in top of route it is also applied to the direct-route
      2019-05-21 14:50:24.545  INFO 138880 --- [imer://expected] PossibleBug-original-route               : 3
      2019-05-21 14:50:24.545  INFO 138880 --- [imer://expected] PossibleBug-original-route               : This should be done once, when the original route is completed i.e. after log 3. When onCompletion is defined in top of route it is also applied to the direct-route
      
      

       

      As can be seen above the log message defined in onCompletion shows up twice. If onCompletion is defined in the end of the route this will not be the case. Also when using modeAfterConsumer (or not specifying mode) it will only show up once. See github project to see this example in action.

       

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jakob.thun Jakob Thun
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: