Reusing endpoints
When an endpoint is going to be used multiple times in a Camel context it is preferable to define it at a single place so that it is used consistently. This recipe will show you a way to do that.
Getting ready
Define your desired routing logic as described in either the Using Camel in a Java application recipe, or the Embedding Camel in a Spring application recipe.
How to do it...
In the XML DSL, define an <endpoint/>
element with an id
attribute and an uri
attribute setting that is set to the URI value you wish to share:
<camelContext xmlns="..."> <endpoint id="restfulOrdersService" uri="jetty:http://localhost:8080/orders"/> <route> <from ref="restfulOrdersService"/> <!-- ... --> </route> </camelContext>
If using the Java DSL, simply define the URI as a String within RouteBuilder
configure()
method:
String restfulOrdersService = "jetty:http://localhost:8080/orders"; from(restfulOrdersService) //...