Copyright © 2009 Bull SAS
This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license,visit http://creativecommons.org/licenses/by-sa/2.0/deed.en or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
$Id: guide.xml 17458 2009-05-26 09:54:10Z alitokmen $
The goal of this document is to describe the Camel OSGi service and how to use it in your applications.
Camel is a light ESB (Enterprise Service Bus) developped by Apache (see http://camel.apache.org/ ). The service provided here is a wrapper of the existing Camel OSGi component. The goal of this wrapper is to manage all the contexts of camel that are running on the gateway in order to concentrate the knowledge of the infrastructure. Therefore, it will be easier to monitor the bus. When an application will use the ESB, it will have to use the service, which will provide the application a new context to work on (deploy new endpoints, new routes, ...).
The Camel service relies on the OSGi bundles of Camel. It uses iPOJO to provides services on the OSGi gateway.
The service implementation contains a wrapper of a Camel context, which is instantiated by the service when an application requires one. This wrapper contains :
Example :
this.from("registry:cxfEndpoint")
will be a lot easier to write than
this.from("cxf://http://localhost:9000/SayHello?serviceClass=org.ow2.jonas.samples.camel.example.cxf.webservice.
api.ISayHello&dataFormat=POJO")
These entries are set from an xml file, that matches the following XSD :
<schema targetNamespace="org.ow2.jonas.samples.camel.registry.impl.file:FileRegistry" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="org.ow2.jonas.samples.camel.registry.impl.file:FileRegistry"> <element name="registry" type="tns:registry"></element> <complexType name="registry"> <sequence maxOccurs="unbounded" minOccurs="0"> <element name="entry" type="tns:entry"></element> </sequence> </complexType> <complexType name="entry"> <sequence maxOccurs="1" minOccurs="1"> <element name="logicalName" type="string"></element> <element name="technicalName" type="string"></element> </sequence> </complexType> </schema>
Therefore, the file that allows the developer to use the previous example is :
<registry xmlns="org.ow2.jonas.samples.camel.registry.impl.file:FileRegistry" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="org.ow2.jonas.samples.camel.registry.impl.file:FileRegistry FileRegistry.xsd"> <entry> <logicalName>cxfEndpoint</logicalName> <technicalName> <![CDATA[ cxf:// http://localhost:9000/SayHello? serviceClass=org.ow2.jonas.samples.camel.example.cxf.webservice.api.ISayHello& dataFormat=POJO ] ]> </technicalName> </entry> </registry>
The service is then able to trigger some useful actions on the Camel contexts it owns, described below. See the javadoc for more details.
// Start a new context for the application
this.camelContextName = this.camelService.startNewContext();
// Stop a Camel context
this.camelService.stop(this.camelContextName);;
...
// Prepare a route to add in the created context
RouteBuilder builder = new RouteBuilder() {
@Override
public void configure() throws Exception {
this.from("joram:queue:queueSample").to("file:///tmp/test");
}
};
// Add the route in the camel context.
this.camelService.addRoutes(builder, this.camelContextName);
...
// Add the registry entries
ClassLoader cl = this.getClass().getClassLoader();
InputStream input = cl.getResourceAsStream("registry.xml");
this.camelService.addRegistry(input, this.camelContextName);
// Remove entries from the registry
ClassLoader cl = this.getClass().getClassLoader();
InputStream input = cl.getResourceAsStream("registry.xml");
this.camelService.removeRegistry(input, this.camelContextName);
// Add the JORAM component
JmsComponent joram = new JmsComponent();
ConnectionFactory connectionFactory;
connectionFactory = (ConnectionFactory) new InitialContext().lookup("CF");
joram.setConnectionFactory(connectionFactory);
JndiDestinationResolver jndiDestinationResolver = new JndiDestinationResolver();
jndiDestinationResolver.setCache(true);
joram.setDestinationResolver(jndiDestinationResolver);
this.camelService.addComponent("joram", joram, this.camelContextName);
...
// Prepare a route to add in the created context
RouteBuilder builder = new RouteBuilder() {
@Override
public void configure() throws Exception {
this.from("joram:queue:queueSample").to("file:///tmp/test");
}
};
...
To deploy the service on the OSGi gateway provided by JOnAS 5, the file
deployment_plans/camel.xml
needs to be put in the
/deploy
directory of the running JOnAS 5. You must see in the command line that the Camel service is started.