blob: 5aab87153232af32035660020ee0520b5328c4eb [file] [log] [blame]
<div class="wiki-content maincontent"><h3>Example of a configuration that shows how to connect to Oracle AQ queues and topics.</h3>
<structured-macro ac:macro-id="4cf21870-0ab2-4f52-a906-fabf122f573a" ac:name="code" ac:schema-version="1"><parameter ac:name="">xml</parameter><plain-text-body>
&lt;beans&gt;
&lt;!-- Allows us to use system properties as variables in this configuration file --&gt;
&lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/&gt;
&lt;broker useJmx="true" persistent="false" xmlns="http://activemq.org/config/1.0"
brokerName="localhost" dataDirectory="${activemq.base}/data" &gt;
&lt;/broker&gt;
&lt;camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"&gt;
&lt;!-- Dependencies: ojdbc.jar and aqjms.jar must be in the activemq lib directory --&gt;
&lt;!-- this camel route will read incoming messages from Oracle --&gt;
&lt;route&gt;
&lt;from uri="oracleQueue:queue:ORACLE_QUEUE"&gt;
&lt;to uri="activemq:queue:queue.inboundOracleAQqueue" &gt;
&lt;/route&gt;
&lt;route&gt;
&lt;!-- NOTE: I have had success with a topic using ActiveMQ 5.3, but not 5.1 --&gt;
&lt;from uri="oracleTopic:topic:ORACLE_TOPIC"&gt;
&lt;to uri="activemq:queue:queue.inboundOracleAQtopic" &gt;
&lt;/route&gt;
&lt;!-- these camel routes will log the messages to the console .... replace them with something more useful!! --&gt;
&lt;route&gt;
&lt;from uri="activemq:queue:queue.inboundOracleAQqueue" &gt;
&lt;to uri="log:oracleAQ.inbound.got_a_queue_message?level=ERROR"&gt;
&lt;/route&gt;
&lt;route&gt;
&lt;from uri="activemq:queue:queue.inboundOracleAQtopic" &gt;
&lt;to uri="log:oracleAQ.inbound.got_a_topic_message?level=ERROR"&gt;
&lt;/route&gt;
&lt;/camelContext&gt;
&lt;!-- without the following bean instantiation, we will get an oracle.jms.AQjmsException with each and every received message --&gt;
&lt;bean id="requiredBeanForOracleAq" class="org.apache.activemq.ActiveMQConnectionFactory" /&gt;
&lt;bean id="connectionFactoryOracleAQQueue" class="oracle.jms.AQjmsFactory" factory-method="getQueueConnectionFactory"&gt;
&lt;constructor-arg index="0"&gt;
&lt;value&gt;jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST ....... (SERVICE_NAME = myDbService)))&lt;/value&gt;
&lt;/constructor-arg&gt;
&lt;constructor-arg index="1" type="java.util.Properties"&gt;
&lt;value&gt;&lt;/value&gt;
&lt;/constructor-arg&gt;
&lt;/bean&gt;
&lt;bean id="connectionFactoryOracleAQTopic" class="oracle.jms.AQjmsFactory"
factory-method="getQueueConnectionFactory"&gt;
&lt;constructor-arg index="0"&gt;
&lt;value&gt;jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST ....... (SERVICE_NAME = myDbService)))&lt;/value&gt;
&lt;/constructor-arg&gt;
&lt;constructor-arg index="1" type="java.util.Properties"&gt;
&lt;value&gt;&lt;/value&gt;
&lt;/constructor-arg&gt;
&lt;/bean&gt;
&lt;bean id="oracleQueueCredentials" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"&gt;
&lt;property name="targetConnectionFactory"&gt;
&lt;ref bean="connectionFactoryOracleAQQueue"&gt;
&lt;/property&gt;
&lt;property name="username"&gt;
&lt;value&gt;foo&lt;/value&gt;
&lt;/property&gt;
&lt;property name="password"&gt;
&lt;value&gt;bar&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id="oracleTopicCredentials" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter"&gt;
&lt;property name="targetConnectionFactory"&gt;
&lt;ref bean="connectionFactoryOracleAQTopic"&gt;
&lt;/property&gt;
&lt;property name="username"&gt;
&lt;value&gt;foo&lt;/value&gt;
&lt;/property&gt;
&lt;property name="password"&gt;
&lt;value&gt;bar&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id="oracleQueue" class="org.apache.camel.component.jms.JmsComponent"&gt;
&lt;property name="connectionFactory" ref="oracleQueueCredentials"&gt;
&lt;/bean&gt;
&lt;bean id="oracleTopic" class="org.apache.camel.component.jms.JmsComponent"&gt;
&lt;property name="connectionFactory" ref="oracleTopicCredentials"&gt;
&lt;/bean&gt;
&lt;/beans&gt;
</plain-text-body></structured-macro>
<p>If you run in an OSGi environment such as <a shape="rect" href="http://servicemix.apache.org">ServiceMix 4</a> then take a look at <a shape="rect" href="http://servicemix.396122.n5.nabble.com/ServiceMix-4-2-Camel-OracleAQ-td421214.html#a421214">this discussion</a> how to install the OracleAQ Client in the OSGi container.</p>
<h4>Oracle SQL code</h4>
<p>You may need to setup OracleAQ, and here is a sample code</p>
<structured-macro ac:macro-id="efdb1a06-1164-41a6-86ee-ce8b6fc792b7" ac:name="code" ac:schema-version="1"><plain-text-body>
BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =&gt; 'queue_message_table', queue_payload_type =&gt; 'SYS.AQ$_JMS_TEXT_MESSAGE');
END;
BEGIN
DBMS_AQADM.CREATE_QUEUE( queue_name =&gt; 'ORACLE_QUEUE', queue_table =&gt; 'queue_message_table');
END;
BEGIN
DBMS_AQADM.START_QUEUE(queue_name =&gt; 'ORACLE_QUEUE');
END;
</plain-text-body></structured-macro>
<p>You can also find more information about OracleAQ and using JMS at: <a shape="rect" href="http://docs.oracle.com/cd/B13789_01/server.101/b10785/jm_exmpl.htm">http://docs.oracle.com/cd/B13789_01/server.101/b10785/jm_exmpl.htm</a></p></div>