I am using Karaf with Apache Camel and have problems creating a JMS
connection factory for OracleAQ (i.e. queues in an Oracle DBS) the right
way. In Java the connection factory can be created like this:
oracle.jms.AQjmsFactory.getQueueConnectionFactory(javax.sql.DataSource
dataSource)
My first thought was to create a JMS connection factory in the Karaf
container but I found no example or explanation specific for Oracle.
Then I tried to create the connection factory inside the same bundle that
contains the Camel route using the datasource from the container (the
datasource was created with a Blueprint file and is working fine with JDBC):
javax.sql.DataSource dataSource = (javax.sql.DataSource) ((new
javax.naming.InitialContext()).lookup("osgi:service/jdbc/av-ds"));
jmsConnectionFactory =
oracle.jms.AQjmsFactory.getQueueConnectionFactory(dataSource);
log.info("DataSource: " + dataSource);
jmsConnectionFactory =
oracle.jms.AQjmsFactory.getQueueConnectionFactory(dataSource);
log.info("Connected to jmsConnectionFactory: " + jmsConnectionFactory);
Unfortunately, it is not working:
2019-01-14 17:09:07.110 INFO [rt_foo] [216 org.apache.camel.camel-core
2.17.6] DataSource: org.apache.commons.dbcp.BasicDataSource@cbfa2fa
2019-01-14 17:09:07.110 INFO [rt_foo] [216 org.apache.camel.camel-core
2.17.6] Connected to jmsConnectionFactory:
oracle.jms.AQjmsQueueConnectionFactory@7f0f88fe
2019-01-14 17:09:12.377 WARN
[org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] [249
org.apache.servicemix.bundles.spring-jms 3.2.18.RELEASE_1] Setup of JMS
message listener invoker failed for destination 'FOO.BAR_QUEUE' - trying to
recover. Cause: Could not create JMS transaction; nested exception is
oracle.jms.AQjmsException: Error creating the db_connection
2019-01-14 17:09:12.397 ERROR
[org.apache.camel.component.jms.DefaultJmsMessageListenerContainer] [249
org.apache.servicemix.bundles.spring-jms 3.2.18.RELEASE_1] Could not refresh
JMS Connection for destination 'FOO.BAR_QUEUE' - retrying in 5000 ms. Cause:
Error creating the db_connection; nested exception is
java.lang.ClassCastException:
org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper cannot
be cast to oracle.jdbc.internal.OracleConnection
The only way I could get OracleAQ JMS to work was to create a new datasource
inside the bundle which I could then use to create the connection factory.
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
<property name="URL" value="jdbc:oracle:thin:@1.2.3.4:1521:FOO"/>
<property name="user" value="foo"/>
<property name="password" value="bar"/>
</bean>
javax.sql.DataSource dataSource = (javax.sql.DataSource)
((org.apache.camel.spring.SpringCamelContext)
camelContext).getApplicationContext().getBean("dataSource");
jmsConnectionFactory =
oracle.jms.AQjmsFactory.getQueueConnectionFactory(dataSource);
But I consider this bad design, because every bundle using JMS will require
its own separate datasource. I hope someone can help with a solution that
works better.
Used versions:
karaf 4.1.1
camel 2.17.6 (with Talend ESB 6.4.1)
Used dependencies in the bundle:
ojdbc7.jar
aqapi.jar
runtime12.jar
jta-1.1.jar
orai18n.jar
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html