lapots
lapots

Reputation: 13415

prevent camel from initializing the endpoint

I have an endpoint in the route that cannot be instatiated locally - due to some missing properties that are unavailable and cannot be accessed in the local environment.

So when I start the application in local environment I get the error org.apache.camel.FailedToCreateRouteException. However in server environment it works fine.

How to prevent camel from initializing endpoint on the local environment (I have a property that allows to find out whether the environent is local or not)? Something like this

<choice>
    <when>
        <simple>{{is.local}} == true</simple>
        <to uri="direct:local.route"/>
    </when>
    <otherwise>
        <to uri="direct:server.route"/>
    </otherwise>
</choice>

But for from clause

Upvotes: 0

Views: 874

Answers (3)

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3191

There is "better" alternative solution. Why don't you inject your parameters as environment variables. Then inject those as properties and you can use use Camel's property resolver to inject the properties in your from() or to().

See here under "propertyinject" http://camel.apache.org/properties.html

Upvotes: 0

Vyacheslav Enis
Vyacheslav Enis

Reputation: 1641

You can use Java DSL for this part only (create simple RouteBuilder) and initialize required "from" part depending on anything you want.

Upvotes: 0

lapots
lapots

Reputation: 13415

Thanks to the idea of MickaëlB to use profiles, I did like this.

I created camel-route-local.xml and camel-route.xml. First file contains routes that should work in the local environment. Second - routes that operates with endpoints that are not for local environment. File camel-context.xml contains camelContext definition definition.

In my main application-context.xml I added these line at the end of the file

 <beans profile="default">
    <import resource="classpath:camel-route.xml"/>
    <import resource="classpath:camel-context.xml"/>
 </beans>

<beans profile="LOCAL">
    <import resource="classpath:camel-route-local.xml"/>
    <import resource="classpath:camel-context.xml"/>
</beans>

Now, if I run local environment - aka set spring profile as LOCAL - it will load camel-route-local.xml with routes that works for local environment (also I got of rid the check for is.local) and if the environment is not LOCAL - aka any other profile - it will load main routes.

Upvotes: 1

Related Questions