title: How to check if a apache camel route exists?
body: <p>I am trying to find if a direct route exists in camel with the help of a try catch block like below. I am looking for a predicate to check if a route exists in camel or not. I could not find anything that directly gives me the answer, so I took the below approach,</p>
  
  <pre><code>&lt;doTry&gt;
      &lt;recipientList&gt;
          &lt;description&gt;Check if a country specific handler is available&lt;/description&gt; 
          &lt;simple&gt;direct:${header.operationName}${body.country}&lt;/simple&gt; 
      &lt;/recipientList&gt;
      &lt;doCatch&gt;
          &lt;exception&gt;org.apache.camel.component.direct.DirectConsumerNotAvailableException&lt;/exception&gt; 
          &lt;recipientList&gt;
              &lt;description&gt;if a country specific handler is not available to to the base&lt;/description&gt; 
              &lt;simple&gt;direct:${header.operationName}&lt;/simple&gt; 
          &lt;/recipientList&gt;
      &lt;/doCatch&gt;
  &lt;/doTry&gt;
  </code></pre>
  
  <p>This means that I am forced to use the exception handler in camel to catch a DirectConsumerNotAvailableException to determine if a route exists. I am looking at an alternate approach where we can use a simple expression like <strong>exists</strong> below,</p>
  
  <pre><code>&lt;choice&gt;
      &lt;when&gt;
          &lt;description&gt;Check if a country specific handler is available&lt;/description&gt;
          &lt;simple&gt;direct:${header.operationName}${body.country} exists&lt;/simple&gt;
          &lt;recipientList&gt;
              &lt;description&gt;country specific handler is available&lt;/description&gt;
              &lt;simple&gt;direct:${header.operationName}${body.country}&lt;/simple&gt;
          &lt;/recipientList&gt;
      &lt;/when&gt;
      &lt;otherwise&gt;
          &lt;recipientList&gt;
              &lt;description&gt;country specific handler is not available then route to generic processing&lt;/description&gt;
              &lt;simple&gt;direct:${header.operationName}&lt;/simple&gt;
          &lt;/recipientList&gt;
      &lt;/otherwise&gt;
  &lt;/choice&gt;
  </code></pre>
  
  <p>Please let me know if something like this can be achieved using some other means.</p>