Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: JMX added

...

And dependencies for the AOP enable server example. These dependencies are of course only needed if you need fullblown full blown AOP stuff using AspejctJ with bytecode instrumentation.

...

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 bean: namespace and springs context:. For configuring ActiveMQ we use broker: and for Camel we of course have camel: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 rescue as it scans for spring annotations in the given package name:. Notice that we don't use version numbers for the camel-spring schema. At runtime the schema is resolved in the Camel bundle. If we use a specific version number such as 1.4 then its IDE friendly as it would be able to import it and provide smart completion etc. See Xml Reference for further details.

Wiki Markup
{snippet:id=e2e1|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:We use Spring annotations for doing IoC dependencies and its component-scan features comes to the rescue as it scans for spring annotations in the given package name:

Wiki Markup
{snippet:id=e3e2|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 also configured in this xml file. We set it up to listen on TCP port 61616.

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.
Notice that we also have enabled the JMXAgent so we will be able to introspect the Camel Server with a JMX Console.

unmigrated-inline-unmigrated-inline-wiki-markup
{snippet:id=e4e3|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:

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

unmigrated-inlineunmigrated-inline-wiki-markup
{snippet:id=e5e4|lang=xml|url=activemq/camel/trunk/examples/camel-example-spring-jms/src/main/resources/META-INF/spring/camel-server.xml}

Notice: The 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 referenced from Camel routes - meaning we can do routing using the JMS Component by just using jms: prefix in the route URI. What happens is that Camel will find in the Spring Registry for a bean with the id="jms". Since the bean id can have arbitrary name you could have named it id="jmsbroker" and then referenced to it in the routing as from="jmsbroker:queue:numbers).to("multiplier");
We use the vm is configured in standard Spring beans, but the gem is that the bean id can be referenced from Camel routes - meaning we can do routing using the JMS Component by just using jms: prefix in the route URI. What happens is that Camel will find in the Spring Registry for a bean with the id="jms". Since the bean id can have arbitrary name you could have named it id="jmsbroker" and then referenced to it in the routing as from="jmsbroker:queue:numbers).to("multiplier");
We use the vm protocol to connect to the ActiveMQ server as its embedded in this application.

...

Switching to a different component is just a matter of using the correct endpoint. So if we had defined a TCP endpoint as: "mina:tcp://localhost:61616" then its just a matter of getting hold of this endpoint instead of the JMS and all the rest of the java code is exactly the same.

Run the Clients

The Clients is started using their main class respectively.

  • as a standard java main application - just start their main class
  • using maven jave:exec

In this sample we start the clients using maven:
mvn compile exec:java -PCamelClient
mvn compile exec:java -PCamelClientRemoting
mvn compile exec:java -PCamelClientEndpoint

Also see the Maven pom.xml file how the profiles for the clients is defined.

Using the Camel Maven Plugin

Note

Require an explanation here about the deployment options of Camel based projects (e.g. running through Maven, creating a host application, deploying into ActiveMQ) and the pros/cons of each.

The Camel Maven Plugin allows you to run your Camel routes directly from Maven. This negates the need to create a host application, as we did with Camel server, simply to start up the container. This can be very useful during development to get Camel routes running quickly.

Code Block
titlepom.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

Clients

The Clients is started using their main class respectively.

  • as a standard java main application - just start their main class
  • using maven jave:exec

In this sample we start the clients using maven:
mvn compile exec:java -PCamelClient
mvn compile exec:java -PCamelClientRemoting
mvn compile exec:java -PCamelClientEndpoint

Also see the Maven pom.xml file how the profiles for the clients is defined.

Using the Camel Maven Plugin

The Camel Maven Plugin allows you to run your Camel routes directly from Maven. This negates the need to create a host application, as we did with Camel server, simply to start up the container. This can be very useful during development to get Camel routes running quickly.

Code Block
titlepom.xml

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

All that is required is a new plugin definition in your Maven POM. As we have already placed our Camel config in the default location (camel-server.xml has been placed in META-INF/spring/) we do not need to tell the plugin where the route definitions are located. Simply run mvn camel:run.

Using Camel JMX

Camel has extensive support for JMX and allows us to inspect the Camel Server at runtime. As we have enabled the JMXAgent in our tutorial we can fire up the jconsole and connect to the following service URI: service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/camel. Notice that Camel will log at INFO level the JMX Connector URI:

Code Block

...
DefaultInstrumentationAgent    INFO  JMX connector thread started on service:jmx:rmi:///jndi/rmi://claus-acer:1099/jmxrmi/camel
...

In the screenshot below we can see the route and its performance metrics:
Image AddedAll that is required is a new plugin definition in your Maven POM. As we have already placed our Camel config in the default location (camel-server.xml has been placed in META-INF/spring/) we do not need to tell the plugin where the route definitions are located. Simply run mvn camel:run.

See Also