LibraryLink ToToggle FramesPrintFeedback

Spring Configuration

You can use a Spring configuration file to configure the following basic aspects of a router application:

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.


Where the preceding configuration can be explained as follows:

1

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.

2

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.

3

Define a camelContext element, which belongs to the namespace, http://activemq.apache.org/camel/schema/spring.

4

Use the package element to specify one or more Java package names. As it starts up, the Spring wrapper automatically instantiates and activates any RouteBuilder classes that it finds in the specified packages.

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]:QueueOrTopicName in your routing rules.


Where the preceding configuration can be explained as follows:

1

Use the class attribute to specify the name of the component class—in this example, the JMS component class is being used. The id attribute specifies the prefix to use for JMS endpoint URIs. For example, with the id equal to jms you can connect to an endpoint like jms:queue:FOO.BAR in your application code.

2

When you set the property named, connectionFactory, Spring implicitly calls the JmsComponent.setConnectionFactory() method to initialize the JMS component at run time.

3

The connection factory property is initialized to be an instance of ActiveMQConnectionFactory (that is, an instance of a FUSE Message Broker message queue).

4

When you set the brokerURL property on ActiveMQConnectionFactory, Spring implicitly calls the setBrokerURL() method on the connection factory instance. In this example the broker URL, vm://localhost, specifies a broker that is co-located in the same Java Virtual Machine (JVM) as the router. The broker library automatically instantiates the new broker when you try to send it a message.

For more details about configuring components in Spring, see List of Components in Component Reference.