與 Oracle AQ 的 JMS 橋接

使用 ActiveMQ Classic > 使用者提交的設定 > 與 Oracle AQ 的 JMS 橋接

展示如何連接到 Oracle AQ 佇列和主題的配置範例。

<beans>
    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

    <broker useJmx="true" persistent="false" xmlns="http://activemq.org/config/1.0"
            brokerName="localhost" dataDirectory="${activemq.base}/data" >
    </broker>

    <camelContext id="camel" xmlns="https://activemq.dev.org.tw/camel/schema/spring">
        <!-- Dependencies: ojdbc.jar and aqjms.jar must be in the activemq lib directory -->

        <!-- this camel route will read incoming messages from Oracle -->
        <route>
            <from uri="oracleQueue:queue:ORACLE_QUEUE">
            <to   uri="activemq:queue:queue.inboundOracleAQqueue" >
        </route>
        <route>
            <!-- NOTE: I have had success with a topic using ActiveMQ Classic 5.3, but not 5.1 -->
            <from uri="oracleTopic:topic:ORACLE_TOPIC">
            <to   uri="activemq:queue:queue.inboundOracleAQtopic" >
        </route>

        <!-- these camel routes will log the messages to the console .... replace them with something more useful!!  -->
        <route>
            <from uri="activemq:queue:queue.inboundOracleAQqueue" >
            <to uri="log:oracleAQ.inbound.got_a_queue_message?level=ERROR">
        </route>
        <route>
            <from uri="activemq:queue:queue.inboundOracleAQtopic" >
            <to uri="log:oracleAQ.inbound.got_a_topic_message?level=ERROR">
        </route>
    </camelContext>

    <!-- without the following bean instantiation, we will get an oracle.jms.AQjmsException with each and every received message -->
    <bean id="requiredBeanForOracleAq" class="org.apache.activemq.ActiveMQConnectionFactory" />

    <bean id="connectionFactoryOracleAQQueue" class="oracle.jms.AQjmsFactory" factory-method="getQueueConnectionFactory">
        <constructor-arg index="0">
            <value>jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST ....... (SERVICE_NAME = myDbService)))</value>
        </constructor-arg>
        <constructor-arg index="1" type="java.util.Properties">
            <value></value>
        </constructor-arg>
    </bean>

    <bean id="connectionFactoryOracleAQTopic" class="oracle.jms.AQjmsFactory"
                factory-method="getQueueConnectionFactory">
        <constructor-arg index="0">
            <value>jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST ....... (SERVICE_NAME = myDbService)))</value>
        </constructor-arg>
        <constructor-arg index="1" type="java.util.Properties">
            <value></value>
        </constructor-arg>
    </bean>

    <bean id="oracleQueueCredentials" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
        <property name="targetConnectionFactory">
            <ref bean="connectionFactoryOracleAQQueue">
        </property>
        <property name="username">
            <value>foo</value>
        </property>
        <property name="password">
            <value>bar</value>
        </property>
    </bean>

    <bean id="oracleTopicCredentials" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
        <property name="targetConnectionFactory">
            <ref bean="connectionFactoryOracleAQTopic">
        </property>
        <property name="username">
            <value>foo</value>
        </property>
        <property name="password">
            <value>bar</value>
        </property>
    </bean>

   <bean id="oracleQueue" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="oracleQueueCredentials">
   </bean>

   <bean id="oracleTopic" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="oracleTopicCredentials">
   </bean>
</beans>

如果您在 OSGi 環境中執行,例如 ServiceMix 4,那麼請查看這個討論,了解如何在 OSGi 容器中安裝 OracleAQ 用戶端。

Oracle SQL 程式碼

您可能需要設定 OracleAQ,以下是一些範例程式碼

BEGIN
 DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table => 'queue_message_table', queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE');
END;        

BEGIN
  DBMS_AQADM.CREATE_QUEUE( queue_name => 'ORACLE_QUEUE', queue_table => 'queue_message_table');
END;

BEGIN
  DBMS_AQADM.START_QUEUE(queue_name => 'ORACLE_QUEUE');
END;  

您也可以在以下網址找到更多關於 OracleAQ 和使用 JMS 的資訊:http://docs.oracle.com/cd/B13789_01/server.101/b10785/jm_exmpl.htm

Apache、ActiveMQ、Apache ActiveMQ、Apache 羽毛標誌和 Apache ActiveMQ 專案標誌是 Apache 軟體基金會的商標。 版權所有 © 2024,Apache 軟體基金會。 根據 Apache 許可證 2.0 授權。