How do I configure endpoints?

There are a few different approaches to configuring components and endpoints.

Using Java Code

You can explicitly configure a Component using Java code as shown in this example

Or you can explicitly get hold of an Endpoint and configure it using Java code as shown in the Mock endpoint examples.

SomeEndpoint endpoint = (SomeEndpoint) camelContext.getEndpoint("someURI");
endpoint.setSomething("aValue");

Using Guice

You can also use Guice as the dependency injection framework. For example see the Guice JMS Example

Using Spring XML

You can configure your Component or Endpoint instances in your Spring XML as follows.

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <jmxAgent id="agent" disabled="true"/>
</camelContext>

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
  <property name="connectionFactory">
    <bean class="org.apache.activemq.ActiveMQConnectionFactory">
      <property name="brokerURL" value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>
  </property>
</bean>

Which allows you to configure a component using some name (activemq in the above example), then you can refer to the component using activemq:[queue:|topic:]destinationName. This works by the SpringCamelContext lazily fetching components from the spring context for the scheme name you use for Endpoint URIs

Using Endpoint URIs

Another approach is to use the URI syntax. The URI syntax supports the query notation. So for example with the Mail component you can configure the password property via the URI

pop3://host:port?password=foo

Referring beans from Endpoint URIs

Available as of Camel 2.0

When configuring endpoints using URI syntax you can now refer to beans in the Registry using the # notation.
If the parameter value starts with a # sign then Camel will lookup in the Registry for a bean of the given type. For instance:

file://inbox?sorter=#mySpecialFileSorter

Will lookup a bean with the id mySpecialFileSorter in the Registry.

See Also

© 2004-2011 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram