Accessing OpenMQ JMS Broker from ServiceMix+Camel

1.2k Views Asked by At

I am trying to get ServiceMix+Camel talking to OpenMQ JMS Broker. I have a Camel route definition defined in Blueprint DSL which posts messages into an ActiveMQ JMS Queue. This is working fine, but I am now trying to convert this to post messages to an instance of OpenMQ running inside a Glassfish4 container.

I'm running the following configuration: JDK 1.7.0_60 ServiceMix 5.1.1 (so Camel 2.13.2)

The documentation on this topic is somewhat minimal, but I've gathered various snippets from Google searches here and here and come up with the following (relevant parts only):

....
  <!-- Post over JMS into Manager -->
  <to uri="openmq:queue:resman"/>
 </route>
</camelContext> 

<bean id="openmq" class="org.apache.camel.component.jms.JmsComponent">
 <property name="connectionFactory">
  <bean class="com.sun.messaging.ConnectionFactory">
   <property name="imqAddressList" value="localhost:7676"/>
  </bean>
 </property>
</bean>

I have the following JMS related "features" enabled in Servicemix/OSGI:

[installed  ] [3.2.4.RELEASE  ] spring-jms
[installed  ] [2.13.2         ] camel-jms

and I have the following OSGI bundles installed and active:

[  89] [Active     ] [            ] [       ] [   50] geronimo-jms_1.1_spec (1.1.1)
[ 126] [Active     ] [            ] [       ] [   50] camel-jms (2.13.2)

The problem I have is a ClassNotFoundException at the point I deploy the Came Route Blueprint into ServiceMix. Here are the relevant snippets from the Stacktrace logged:

org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to instantiate components
Caused by: java.lang.NoClassDefFoundError: javax/jms/JMSContext
Caused by: java.lang.ClassNotFoundException: javax.jms.JMSContext not found by org.apache.geronimo.specs.geronimo-jms_1.1_spec [89]

So on the assumption this is an OSGI bundling issue, I've dug down into the Camel "features" just to confirm the dependencies:

karaf@root> features:info camel-jms
Description of camel-jms 2.13.2 feature
----------------------------------------------------------------
Feature has no configuration
Feature has no configuration files
Feature depends on:
  spring [3.2,4)
  spring-jms [3.2,4)
  camel-core 2.13.2
Feature contains followed bundles:
  mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1 start-level=50
  mvn:commons-pool/commons-pool/1.6 start-level=50
  mvn:org.apache.geronimo.specs/geronimo-jms_1.1_spec/1.1.1 start-level=50
  mvn:org.apache.camel/camel-jms/2.13.2 start-level=50

So it appears that it is the "geronimo-jms_1.1_spec" that is causing the stack trace as it can't find JMSContext. I making a big assumption that as ApacheMQ must be using the same JMS class, so it must be in the environment somewhere. Also, JMSContext seems to be a JMS 2.0 API interface, so is the issue here that the geronimo-jms_1.1_spec bundle is trying to reference a JMS2 API?

I also have the issue of getting the client JARs for OpenMQ installed into the environment. The OpenMQ client JARs shipped with Glassfish4 are plain JARs and not OSGI bundles (see https://java.net/jira/browse/MQ-328), so I plan to either use the "file:wrap" feature to deploy this into ServiceMix, or otherwise unpack and re-pack into the JAR containing my Beans. I don't think this is related to this problem, but I could be wrong.

1

There are 1 best solutions below

0
On

OK, managed to work this one out finally. The clue was in the reference to javax.jms.JMSContext which is new in the JMS 2.0 API. I was attempting to use the OpenMQ client libraries (imq.jar and jms.jar) taken from the Glassfish4 distribution, which is at JEE7 and hence JMS v1.1. ServiceMix 5.1.1 is still at JMS V1.1, hence the ClassNotFoundException.

Solution: When connecting to an instance of OpenMQ running under Glassfish4, you need to download and use the OpenMQ client libraries from the previous Glassfish 3.2.2 release. You can obtain this release release from the Glassfish project archives here.

Tests so far show this to be working fine, so if I find anything of relevance going forward I'll come back and update this post.