Versions Compared

Key

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

...

Code Block
xmlns:camel="http://activemq.apache.org/camel/schema/spring"
http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"

CamelContext

CamelContext is the heart of Camel its where all the routes, endpoints, components, etc. is registered. So we setup a CamelContext and the spring XML files looks like:

...

We want to store the web service request as a file before we return a response. To do this we want to send the file content as a message to an endpoint that produces the file. So we need to do two steps:

...

Both Camel and Spring has annotations that can be used to configure and wire trivial settings more elegantly. Camel has the endpoint annotation @EndpointInjected that is just what we need. With this annotation we can inject the endpoint into our service. The annotation takes either a name or uri parameter. The name is the bean id in the Registry. The uri is the URI configuration for the endpoint. Using this you can actually inject an endpoint that you have not defined in the camel context. As we have defined our endpoint with the id backup we use the name parameter.

Code Block
java
java
    @EndpointInject(name = "backup")
    private ProducerTemplate template;

Camel is smart as @EndpointInject @EndpointInjected supports different kinds of object types. We like the ProducerTemplate so we just keep it as it is.
Since we use annotations on the field directly we do not need to set the property in the spring xml file so we change our service bean:

...

Running the unit test with mvn test reveals that it works nicely.

And since we use the @EndpointInject @EndpointInjected that refers to the endpoint with the id backup directly we can loose the template tag in the xml, so its shorter:

...

Then we avoid to duplicate the name and if we rename the endpoint name then we don't forget to change it in the code also.TODO: Add more links to Camel stuff

TODO: Link to other tutorials
TODO: TOC
TODO: Resources