But this is not the case, when you work in big companies where the infrastructure is separated from the teams in charge to design/build/deploy and release the application. As a developer you don't have access to the acceptance or production environment. This means that you must provide different configuration files to the builder team and/or release management in order to deploy your application in development, acceptance and production environment.
Obviously, the name of the servers are not the same and the infrastructure is in charge to manage the queues servers. In this environment, infra will never accept that the queues definition or creation of the queuing engine are under the responsibility of the developer(s). Thus, it will not be possible in your spring DSL file (or Camel Java DSL classes) to declare your queuing engine like this :
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
<property name="brokerURL" value="vm://localhost:61616" / >
remark: vm://localhost:61616 must be changed to serverName.intranet.domainName:port
depending on queuing engine deployed in the different environment.
To make Camel independent of its queuing engine :
- Size of the queue,
- Size of the messages accepted on the queue,
- Persistence of the messages
1) Add the required bundles to your ServiceMix 4 osgi server to allow it to work with ActiveMq. Normally, the features transaction and activemq are activated by default in the file etc/org.apache.servicemix.features.cfg. So, you don't have to do anything else except if you use ServiceMix Kernel. In this case, you have to add the bundles manually or add a link (in the config file) to the features.xml file where the bundles have been declared
2) Create a spring xml file where the parameters of the queuing engine are defined. Luckily, such a file already exists and is available from Apache ServiceMix 4 project. So, copy the file into the deploy folder of ServiceMix 4 or Servicemix 4 Kernel
3) Create a osgi-queueservice.xml file containing the following lines and copy it in the deploy folder of ServiceMix
<?xml version="1.0" encoding="UTF-8"? >
<bean id="active-mq" class="org.apache.activemq.camel.component.ActiveMQComponent" />
<osgi:service id="osgiqueuingservice" ref="active-mq" interface="org.apache.camel.Component"/>
When the spring file will be at the server startup loaded by Spring (though its Application context), it will create the bean "active-mq" and instantiate the class : org.apache.activemq.camel.component.ActiveMQComponent.
- No parameters are provided to the ActiveMqComponent like brokerUrl, ...
- If you need to work with another JMS queuing engine, you can replace the class ActiveMQComponent by : org.apache.camel.component.jms.JmsComponent
Next it will create an OSGI service called "osgiqueuingservice" and expose it through the interfaces : org.apache.camel.Component
Remark : As JmsComponent, ActiveMqComponent implements this interface, the OSGI service is generic. So you could parameterized it using a property file (cfg file in the ServiceMix world)
4) The last step is very simple. In your camel config file, you add a reference to your osgi service in order to retrieve the queuing engine like this :
<osgi:reference id="queuingservice" interface="org.apache.camel.Component" />
Please remark that you import the Component interface. So, Camel becomes independent of the queuing engine used (WebSphere, TIBCO, ActiveMQ, ...)
and in your Camel route :
<camel:from uri="queuingservice:queue:in" />