Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Spring config file is placed under META-INF/spring as this is the default location used by the Camel Maven Plugin, which we will later use to run our server.

...

First we need to do the standard scheme declarations in the top. In the camel-server.xml

...

we are using spring beans as the default namespace and springs context:. For configuring ActiveMQ we use broker: and for Camel we of course have :camel.

Wiki Markup
{snippet:id=e1|lang=xml|url=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml}

We use Spring annotations for doing IoC dependencies and its component-scan features comes to the resource as it scans for spring annotations in the given package name:

Wiki Markup
{snippet:id=e2|lang=xml|url=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml}

Camel will of course not be less than Spring in this regard so it supports a similar feature for scanning of Routes. This is configured as shown below:

Wiki Markup
{snippet:id=e3|lang=xml|url=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml}

The ActiveMQ JMS broker is configured in this xml file. We set it up to listen on TCP port 61616.

Wiki Markup
{snippet:id=e4|lang=xml|url=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml}

As this examples uses JMS then Camel needs a JMS component that is connected with the ActiveMQ broker. This is configured as shown below:

Wiki Markup
{snippet:id=e5|lang=xml|url=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml}

Notice: The JMS component is configured in standard Spring beans, but the gem is that the bean id can be reference in Camel routes so we can do routing with the jms: prefix in the URIs and Camel will find this bean in the Registry and use this JMS Component. If you don't like jms you can name the bean id as you like (eg activemq, myjmsbroker, messaging etc). We use the vm protocol to connect to the ActiveMQ server as its embedded in this application.

component-scan

Defines the package to be scanned for Spring stereotype annotations, in this case, to load the "multiplier" bean

camel-context

Defines the package to be scanned for Camel routes. Will find the ServerRoutes class and create the routes contained within it

jms bean

Creates the Camel JMS component

...