This document provides steps to connect an Oracle database Advanced Queuing (AQ) to a Java Message Service (JMS) application using Oracle Messaging Gateway. It involves:
1. Configuring the Oracle database by creating a schema, queue table, and queue for AQ.
2. Configuring WebLogic Server by defining a JMS foreign server pointing to the database, connection factories, and destinations for the queue.
3. Developing a message-driven bean in Java EE that uses JMS to listen for and process messages from the AQ queue.
4. Testing the integration by enqueueing a message to the database queue and verifying it is received and processed by the message-driven
This document provides steps to connect an Oracle database Advanced Queuing (AQ) to a Java Message Service (JMS) application using Oracle Messaging Gateway. It involves:
1. Configuring the Oracle database by creating a schema, queue table, and queue for AQ.
2. Configuring WebLogic Server by defining a JMS foreign server pointing to the database, connection factories, and destinations for the queue.
3. Developing a message-driven bean in Java EE that uses JMS to listen for and process messages from the AQ queue.
4. Testing the integration by enqueueing a message to the database queue and verifying it is received and processed by the message-driven
This document provides steps to connect an Oracle database Advanced Queuing (AQ) to a Java Message Service (JMS) application using Oracle Messaging Gateway. It involves:
1. Configuring the Oracle database by creating a schema, queue table, and queue for AQ.
2. Configuring WebLogic Server by defining a JMS foreign server pointing to the database, connection factories, and destinations for the queue.
3. Developing a message-driven bean in Java EE that uses JMS to listen for and process messages from the AQ queue.
4. Testing the integration by enqueueing a message to the database queue and verifying it is received and processed by the message-driven
http://download.oracle.com/docs/cd/E14571_01/web.1111/e13738/aq_jms.htm#CJACBCEJ First, create a schem a in a database: connect / as sy sdba; create user jmsuser identified by jmsuser; Grant it required priviledges: grant connect, resource to jmsuser; Grant aq_user_role TO jmsuser ; Grant ex ecute ON sy s.dbm s_aqadm TO jmsuser; Grant ex ecute ON sy s.dbm s_aq TO jmsuser; Grant ex ecute ON sy s.dbm s_aqin TO jmsuser; Grant ex ecute ON sy s.dbm s_aqjms TO jm suser; Next reconnect as jmsuser: connect jmsuser / jm suser; Create queue table and queue: dbm s_aqadm.create_queue_table( queue_table=>my QueueTable, queue_payload_type=>'sys.aq$_ jms_message', multiple_consumers=>false ); dbm s_aqadm.create_queue( queue_name=>'userQueue', queue_table=>'myQueueTable' ); Start the queue: dbms_aqadm .start_queue(queue_ name=>'userQueue'); Start the Weblogic server and create a datasource pointing to the new queue (based on OTN documentation): Select the Oracle Thin Driver. Select the driver type based on the type of transactions required for AQ JMS: o Select a non-XA based JDBC driver for use w ith AQ JMS in local transactions. o Select a XA based JDBC driver for use with AQ JMS in either in global transactions or in local transactions. When configuring a data source for non-XA drivers, do not select the Supports Global Transactions option. This release does not support non-XA JDBC driver data sources with any of the global transaction options such as LLR, JTS, and Emulate Two-Phase Commit. If the global transaction option is selected, the server instance logs a warning message. Global transactions are suppor ted with XA-based JDBC dr ivers. Configure the database user nam e and password in the data sour ce connection pool configuration. Identity-based connection pools are not supported. Create a JMS Sy stem Module Create a JMS Foreign Serv er In y our JMS Foreign Server configuration: Specify oracle.jms.AQjmsInitialContextFactory as the JNDI Initial Context Factory: Specify the datasource JNDI property which is the JNDI location of a locally bound WLS data source: Click on Connection Factories tab and define a connection factory: You have to provide only Name, Local JNDI Name and Remote JNDI Name attributes. Depending on the connection factory ty pe (JMS interface) you want to choose you must provide one of the predefined Remote JNDI Names: Remote JNDI names for AQ JMS Connection Factories: Remote JNDI Name JMS Interface QueueConnectionFactory javax.jms.QueueConnectionFactory TopicConnectionFactory javax.jms.TopicConnectionFactory ConnectionFactory jav ax .jms.ConnectionFactory XAQueueConnectionFactory javax.jms.XAQueueConnectionFactory XATopicConnectionFactory javax.jm s.XATopicConnectionFactory XAConnectionFactor y jav ax .jm s.XAConnectionFactory
Next define a destination, for example:
Again, for Remote JNDI Name you need to use special notation as in table below: AQ JMS Prefix Value of the JMS Interface AQ JMS Prefix Value JMS Interface Queues/<aq_queue_name> Javax.jms.Queue Topics/<aq_queue_name> javax.jms.Topic Where <aq_queue_name> is the name of AQ queue in the database Sav e and activ ate changes Next build your MDB. Open JDeveloper, choose New Application with Java EE Web Application template: Accept all default settings on next couple of screens and finally click Finish Right-click on the Model project, choose New and then Business Tier -> EJB -> Message-Driven Bean Enter a bean name and previously defined JNDI nam e of the destination as a mapped name: Accept all defaults untill y ou reach Finish JDev eloper will generate a MDB class for you: Add the name attribute to the MessageDriven annotation as follows: @MessageDriven(name = "AQMDBTest", mappedNam e = "/jms/aq/userQueue") Implement the onMessage method, for example: public void onMessage(Message m essage) { if (message instanceof TextMessage) { try { Sy stem.out.println("AQMDBTest: text message "+((TextMessage)message).getText()+" processed"); } catch (JMSException e) { e.printStackTrace(); } } else { System.out.println("AQMDBTest: generic message "+message.toString()+" of type "+m essage.getClass().getName()+" processed"); } } Open weblogic-ejb-jar.xm l and add the following configuration: <?xml version = '1.0' encoding = 'windows-1252'?> <weblogic-ejb-jar xm lns:xsi="http://www.w3.org/2001/XMLSchema-instance" x si:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd" x mlns="http://www.bea.com /ns/w eblogic/weblogic-ejb-jar"> <weblogic-enterprise-bean> <ejb-name>AQMDBTest</ejb-name> <message-driven-descriptor> <pool> <max -beans-in-free-pool>1</max-beans-in-free-pool> <initial-beans-in-free-pool>1</initial-beans-in-free-pool> </pool> <destination-jndi-nam e>/jms/aq/userQueue</destination-jndi-name> <connection-factory-jndi-name>/jm s/aq/jmsCF</connection-factory-jndi-name> </message-driven-descriptor> </weblogic-enterprise-bean> </weblogic-ejb-jar> Pay attention to use the same name in ejb-name element as in annotation in the bean class ! This configures the connection-factory-jndi-name and points it to the connection factory defined in AQ Foreing Server. If you want to choose XA datasource and XAQueueConnectionFactory you need to define ONLY ONE bean in the pool, in other case you will get an error: oracle.jms.AQjm sEx ception: Internal error: Cannot obtain XAConnection weblogic.comm on.resourcepool.ResourceLimitException: No resources currently available in pool JMSUserDS to allocate to applications, please increase the size of the pool and retry.. Deploy the application to Weblogic server. Next use SQL/Plus to log in to the database (using jmsuser user) and try to enqueue some messages to the queue: create or replace PROCEDURE ENQUEUE_TEXT( payload IN VARCHAR2 ) AS enqueue_options DBMS_AQ.enqueue_options_t; m essage_properties DBMS_AQ.message_properties_t; m essage_handle RAW (16); user_ prop_ar ray SYS.aq$_jms_userproparray; AGENT SYS.aq$_agent; header SYS.aq$_jm s_header; MESSAGE SYS.aq$_jms_ message; BEGIN AGENT := SYS.aq$_agent ('', NULL, 0); AGENT.protocol := 0; user_ prop_ar ray := SYS.aq$_jms_userproparray (); header := SYS.aq$_jms_header (AGENT, '', 'aq1', '', '', '', user_prop_array); MESSAGE := SYS.aq$_jms_m essage.construct (0); MESSAGE.set_ text (pay load); MESSAGE.set_ user id ('Userid_if_ reqd'); MESSAGE.set_ string_property ('JMS_OracleDeliveryMode', 2); --(header, length(message_text), m essage_text, null); DBMS_AQ.enqueue (queue_name => 'userQueue', enqueue_ options => enqueue_options, message_properties => message_properties, payload => MESSAGE, msgid => message_handle ); COMMIT; END ENQUEUE_TEXT; DECLARE PAYLOAD VARCHAR2(200); BEGIN PAYLOAD := 'Hello from AQ !'; ENQUEUE_TEXT( PAYLOAD => PAYLOAD ); END; Open the <serv er_name>.out file in the <domain_home>/servers/<server_name>/logs directory and look for the text: AQMDBTest: tex t message Hello from AQ ! processed This indicates that y our MDB is working !