Apache Camel and WebLogic JMS

Following my last post about my experiences with Apache Camel I wanted to try something a little more advanced. I decided that this time I would add my incoming soap message to a WebLogic JMS Queue.

Creating a JMS queue in WebLogic is beyond the scope of this post. But there should be plenty of guides out there for you to look at. Basically you just need to create a JMS Connection Factory and a JMS Queue attached to the same SubDeployment.

As always, for this series of posts, you can find my example source code on Github here

Maven Dependencies

In addition to the dependencies need in my last example we need to add the camel-jms package.

<dependency>
<artifactId>camel-jms</artifactId>
<groupId>org.apache.camel</groupId>
<version>2.18.0</version>
</dependency>

This will allow us to work with JMS queues.

Spring Configuration

In addition to the configuration of Spring in the last example, we need to add a new section to our spring-ws-servlet.xml file.

<!-- Connection Factories -->
<bean id="weblogic" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="orderConnectionFactory"/>
</bean>
<jee:jndi-lookup id="orderConnectionFactory" jndi-name="jms/OrderConnectionFactory"/>

This will tell Spring about our WebLogic JMS Connection Factory so it can be used in our code. The observant reader might notice that we added a new xml prefix (jee) which we of course need to add to our namespace declarations so that our root element now look like this

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:camel="http://camel.apache.org/schema/spring"
 xmlns:jee="http://www.springframework.org/schema/jee"
 xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">

Camel Route

In our Camel Route we can now reference our JMS queue with something like this

package dk.moerks.wlsjms.routes;

import dk.moerks.wlsjms.schemas.OrderRequest;
import org.apache.camel.ExchangePattern;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.JaxbDataFormat;

public class OrderRoute extends RouteBuilder {
public void configure() throws Exception {
JaxbDataFormat jaxb = new JaxbDataFormat();
jaxb.setContextPath(OrderRequest.class.getPackage().getName());

from("spring-ws:rootqname:{http://moerks.dk/wlsjms/schemas}OrderRequest?endpointMapping=#endpointMapping")
.setExchangePattern(ExchangePattern.InOnly)
.to("jms:queue:./OrderSystemModule!OrderQueue");
}
}

This will take the incoming soap message and add it to our "OrderQueue". There are a few important notes to be made here though. First you will notice that I used a . in front of the Queue Name. This tells WebLogic to use local lookup on the server connected to. Next you will notice that we have added our System Module to the name. This is because of how WebLogic names the JMS queues internally. The name can be found by clicking on the Queue in the console. It follows the rule <SystemModuleName>!<QueueName> though, so it should be fairly easy to deduct.

That is it. For a full example you can look at my example on Github here