title: Apache Camel - Parallel Routes Inflight Exchanges
body: <p>I have a Camel context with many routes that starts every 15m with Timer Component.</p>
  
  <p>These routes set some properties in exchange (Target host, Query and Current Date that I use a Processor to get date, -12 hours and transform to GMT).</p>
  
  <p>After set these properties, using Direct, another route is called to execute the HTTP Get. When the Request finished, another Route is called to Post the return on Artemis ActiveMQ.</p>
  
  <p>The project is deployed on Wildfly 13.</p>
  
  <p>The problem is:
  Sometimes the routes simply freeze. Don't start after 15 minutes.
  When I try to stop/start the route, I got the follow log:</p>
  
  <pre><code>[0m[0m08:27:45,230 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (Camel (camel-example) thread #70 - ShutdownTask) There are 1 inflight exchanges: InflightExchange: [exchangeId=ID-exchange-ID, fromRouteId=Route1, routeId=GetDataAutoBySinceTime, nodeId=toD7, elapsed=0, duration=216958569]
  [0m[0m08:27:46,231 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (Camel (camel-example) thread #70 - ShutdownTask) Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 299 seconds. Inflights per route: [Route1 = 1]
  [0m[0m08:27:46,231 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (Camel (camel-example) thread #70 - ShutdownTask) There are 1 inflight exchanges: InflightExchange: [exchangeId=ID-exchange-ID, fromRouteId=Route1, routeId=GetDataAutoBySinceTime, nodeId=toD7, elapsed=0, duration=216959570]
  [0m[0m08:27:47,231 INFO  [org.apache.camel.impl.DefaultShutdownStrategy] (Camel (camel-example) thread #70 - ShutdownTask) Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 298 seconds. Inflights per route: [Route1 = 1]
  </code></pre>
  
  <p>I don't know if some processes are stuck making it impossible another processes to start.</p>
  
  <p>I thought to remove the generic routes (<code>PostMessageInActiveMQ</code> and 
  <code>GetDataAutomaticallyBySinceTime</code> and to implements the same code in another routes (<code>Route1</code>, <code>Route2</code> and <code>Route3</code>) but I don't think this is the best approach.</p>
  
  <p>Routes:</p>
  
  <p>Route1 (Route2 and Route3 are almost the same, just change properties values)</p>
  
  <pre><code>from("timer:Route1Timer?period=15m")
   .routeId("Route1")
   .autoStartup(false)
   .setProperty("targetAddress", simple("hostname.route1"))
   .process(new GetCurrentDate())
   .setProperty("query",
            simple("DataQuery%26URI=Route1%26format=xml%26Mode=since-time%26p1=${header.currentDate}"))
   .to("direct:GetDataAutoBySinceTime");
  </code></pre>
  
  <p>GetDataAutomaticallyBySinceTime</p>
  
  <pre><code>from("direct:GetDataAutoBySinceTime")
   .routeId("GetDataAutoBySinceTime")
   .autoStartup(true)
   .removeHeaders("*")
   .setHeader(Exchange.HTTP_METHOD, constant("GET"))
   .toD("http4:${header.targetAddress}/command=${header.query}%26httpClient.socketTimeout=3000")
   .convertBodyTo(String.class, "utf-8")
   .to("direct:PostMessageInActiveMQ");
  </code></pre>
  
  <p>PostMessageInActiveMQ</p>
  
  <pre><code>CamelArtemisComponent components = new CamelArtemisComponent();
  getContext().addComponent("artemis", components.getArtemisComponent());
  
  from("direct:PostMessageInActiveMQ")
   .routeId("PostMessageInActiveMQ")
   .autoStartup(true)
   .convertBodyTo(String.class, "utf-8")
   .inOnly("artemis:ARTEMIS.QUEUE");
  </code></pre>
  
  <p>Entire code: <a href="https://github.com/vitorvr/camel-example" rel="nofollow noreferrer">https://github.com/vitorvr/camel-example</a></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Camel Version: 2.22.0</p>