You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by fred <fr...@gmx.net> on 2019/01/15 10:16:27 UTC
How can I create a JMS connection factory for OracleAQ?
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
Re: How can I create a JMS connection factory for OracleAQ?
Posted by fred <fr...@gmx.net>.
cschneider wrote
> You showed how you get the DataSource from jndi but not how you created
> it.
> Do you use a pax-jdbc config for this?
>
> Christian
The datasource feature is build with maven and based on a blueprint file.
The config parts that seem relevant are below. (I didn't work on this
project when the datasource was created and don't know exactly why it was
done this way.)
So the datasource class is org.apache.commons.dbcp.BasicDataSource and
needed is OracleDataSource which is only the driverClassName property. I'm
not sure how to fix this.
Can the BasicDataSource give me somehow an OracleDataSource?
Should I change the bean class in the blueprint to OracleDataSource? (Would
probable require changing a lot of config properties and it would loose
special capabilities that the BasicDataSource has.)
Or do I have to create a datasource by other means? (I'm not sure how
pax-jdbc works.)
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:enc="http://karaf.apache.org/xmlns/jasypt/v1.0.0">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.pool.OracleDataSource"
/>
...
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="de.foo.datasource.name" value="ds-oracle-av" />
<entry key="osgi.jndi.service.name" value="jdbc/av-ds" />
</service-properties>
</service>
</blueprint>
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Re: How can I create a JMS connection factory for OracleAQ?
Posted by Christian Schneider <ch...@die-schneider.net>.
You showed how you get the DataSource from jndi but not how you created it.
Do you use a pax-jdbc config for this?
Christian
Am Mi., 16. Jan. 2019 um 14:44 Uhr schrieb fred <fr...@gmx.net>:
>
> You can create just one DataSource and expose it as an OSGi service. There
> are several ways to do that, like pax-jdbc.
>
> After that, you can just reference the dataSource at your bundle and
> connect
> to the OracleAQ.
>
> --
>
> I think that's what I tried to do, but it did not work:
> javax.sql.DataSource dataSource = (javax.sql.DataSource) ((new
> javax.naming.InitialContext()).lookup("osgi:service/jdbc/av-ds"));
> jmsConnectionFactory =
> oracle.jms.AQjmsFactory.getQueueConnectionFactory(dataSource);
>
> Errormessage when accessing JMS:
> 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
>
> To me, it seems that by getting the datasource as an OSGi service, it is
> weirdly wrapped or proxied in a way that the Oracle QueueConnectionFactory
> cannot work with (and I don't know how to get around this).
>
>
>
> --
> Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
>
--
--
Christian Schneider
http://www.liquid-reality.de
Computer Scientist
http://www.adobe.com
Re: How can I create a JMS connection factory for OracleAQ?
Posted by fred <fr...@gmx.net>.
You can create just one DataSource and expose it as an OSGi service. There
are several ways to do that, like pax-jdbc.
After that, you can just reference the dataSource at your bundle and connect
to the OracleAQ.
--
I think that's what I tried to do, but it did not work:
javax.sql.DataSource dataSource = (javax.sql.DataSource) ((new
javax.naming.InitialContext()).lookup("osgi:service/jdbc/av-ds"));
jmsConnectionFactory =
oracle.jms.AQjmsFactory.getQueueConnectionFactory(dataSource);
Errormessage when accessing JMS:
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
To me, it seems that by getting the datasource as an OSGi service, it is
weirdly wrapped or proxied in a way that the Oracle QueueConnectionFactory
cannot work with (and I don't know how to get around this).
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html
Re: How can I create a JMS connection factory for OracleAQ?
Posted by Castor <yg...@gmail.com>.
You can create just one DataSource and expose it as an OSGi service. There
are several ways to do that, like pax-jdbc.
After that, you can just reference the dataSource at your bundle and connect
to the OracleAQ.
--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html