You can use a Spring configuration file to configure the following basic aspects of a router application:
Specify the Java packages that contain RouteBuilder
classes
Define routing rules in XML
Configure components
In addition to these core aspects of router configuration you can take advantage of the generic Spring mechanisms for configuring and linking together Java objects within the Spring container.
The Spring configuration file for your router application must be stored in the following directory, relative to your
CLASSPATH
(that is, the parent of META-INF
must appear on your
CLASSPATH
):
META-INF/spring/
The Spring container reads any file that matches the pattern META-INF/spring/*.xml
and, there
can be more than one such file. For the examples discussed here, the Spring configuration is stored in a single file, which is
called camel-context.xml
.
Example 2.2 shows a basic Spring XML configuration file that instantiates and activates
RouteBuilder
objects defined in the my.package.name
Java package.
Example 2.2. Basic Spring XML Configuration
<?xml version="1.0" encoding="UTF-8"?> <!-- Configures the Camel Context--> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsdhttp://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<package>
my.package.name
</package></camelContext> </beans>
Where the preceding configuration can be explained as follows:
This line specifies the location of the Spring framework schema. The URL should represent a real, physical location from where you can download the schema. The version of the Spring schema currenlty supported by FUSE Mediation Router is Spring 2.0. | |
This line specifies the location of the Camel context schema. The URL shown in this example always points to the latest version of the schema. | |
Define a | |
Use the |
To configure router components, use the generic Spring bean configuration mechanism
(which implements a dependency injection configuration pattern). That
is, you define a Spring bean
element to create a component instance,
where the class
attribute specifies the full class name of the relevant
FUSE Mediation Router component, and the properties
element is used to set Bean properties
on the component class.
Example 2.3 shows how to configure a JMS component using Spring
configuration. This component configuration enables you to access endpoints of the format
jms:[queue|topic]:
in your
routing rules.QueueOrTopicName
Example 2.3. Configuring Components in Spring
<?xml version="1.0" encoding="UTF-8"?> <beans ... > <camelContext useJmx="true" xmlns="http://activemq.apache.org/camel/schema/spring"> <!-- Java packages (not shown) ... --> </camelContext> <!-- Configure the default ActiveMQ broker URL --> <bean id="jms" class="org.apache.camel.component.jms.JmsComponent"><property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
</bean> </property> </bean> </beans>
Where the preceding configuration can be explained as follows:
Use the | |
When you set the property named, connectionFactory, Spring implicitly calls the
| |
The connection factory property is initialized to be an instance of | |
When you set the brokerURL property on |
For more details about configuring components in Spring, see List of Components in