Yesterday we couldn’t get the JNDI-looked-up JMS connection factory-ish thing to Just Work as a Spring DefaultMessageListenerContainer ConnectionFactory — Spring said it couldn’t convert a org.apache.activemq.ra.ActiveMQConnectionFactory to a javax.jms.ConnectionFactory.
Next, we noticed that the activemq-jms-ds.xml configuration file was exposing a QueueConnectionFactory instead of a full-fledged ConnectionFactory and thought that might be the issue, so we modified that configuration to try to expose a javax.jms.ConnectionFactory, but we still got the same error upon build-n-deploy.
Finally, we tried using the Spring jms:jca-listener-container element instead of a plain DefaultMessageListenerContainer bean, and specified our JNDI-looked-up ConnectionFactory as the resource adapter for the jca-listener-container, but now upon deploy Spring said it couldn’t convert an org.apache.activemq.ra.ActiveMQConnectionFactory to a javax.resource.spi.ResourceAdapter.
Perhaps It’s Supposed to Be Resource Adapter Specific?
The Java Connector 1.5 deployment descriptor schema contains this description for the connection-impl-class element:
The element connectionfactory-impl-class specifies the fully qualified name of the ConnectionFactory class that implements resource adapter specific ConnectionFactory interface.
Now the examples I see, such as…
- The ActiveMQ JNDI Support page in the section titled Sample Code
- Slide 14 of this presentation (PDF)
- This Oracle/WebSphere example (see the jndiLookup calls)
…show a context lookup call being cast to a TopicConnectionFactory or QueueConnectionFactory, and it looks easy as pie. So why isn’t it working like I expect?
A Hmm or Two
Hmm… There’s a whole chapter in the Spring manual dedicated to JCA. Section 21.2.2. ConnectionFactory configuration in Spring just shows what I’m already doing, though, with the JndiObjectFactoryBean. Seems like it should just work!
Double-hmm… I found the API docs for the org.apache.activemq.ra.ActiveMQConnectionFactory class, and it says it implements javax.jms.ConnectionFactory! If so, it surely seems that it should be usable as a javax.jms.ConnectionFactory from the Spring bean file.
The activemq-ra.rar file I deployed to JBoss I think I got from Keith (maybe he built it from the example on the ActiveMQ site?) Since some of the reading I was doing showed a .rar file name in the form activemq-ra-version.rar, I wondered if my activemq-ra.rar was an old one — and maybe the class cast errors I was getting stemmed from that! I found a file named activemq-rar-5.1.0.rar in the lib\optional directory of my apache-activemq-5.1.0 installation, and deployed that instead of the one with no version in its name…but still the same error.
I had the thought that maybe I’d try to do some kind of checking at runtime to see if the JNDI-looked-up connectionFactory object thought it implemented javax.jms.ConnectionFactory, so in my little test class I added this line:
private javax.jms.ConnectionFactory connectionFactory;
Eclipse complained saying it didn’t know about the javax.jms package, so I added the following dependency to my pom.xml file:
<dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jms_1.1_spec</artifactId> <version>1.1.1</version> </dependency>
When I deployed I still had the same issue though.
Time to post a question somewhere! …Looks like we’ll need a Part 5.