Oracle DBA Tips Corner |
|
Using Oracle's Advanced Queuing with JMS - (AQ-JMS)
by Jeff Hunter, Sr. Database Administrator
Contents
Overview
This example will include an Enterprise Application Archive (EAR)
consisting of two modules:
This module will contain a single Message Driven Bean (MDB) named
parallelMDBBean. The purpose of this bean is to accept
incoming JMS messages that describe a task or job. Each job will use
JDBC to insert a fixed number of rows into a database table. The quantity
of rows inserted into the table and their field values will be communicated
through attributes of the JMS message. The table name will be dataset
and will be created dynamically by the application. The table will have the
following fields:
The Message Driven Mean will use the INSERT_DT value for all rows
inserted by the same job. By doing this, the order in which job processing
occurred and any parallelism whithin the concurrent execution of multiple
MDB's can be observed.
The Web module implements two servlets:
Save the file as OracleJmsApp.ear.
If you are using an OC4J instance being managed by the DCM (within the full release of 9iAS), then changes can
be applied either:
For the purpose of this example, the AQ table will be run by the Oracle user "AQ_ADMIN/AQ_ADMIN"
created on a database named "O920NT":
NOTE:
Now, edit the data-sources.xml file located in $ORACLE_HOME/j2ee//config/data-sources.xml.
Add the following data-source, which should reference the schema containing the Queue defined
above:
NOTE:
Insert the following definition into the "application.xml" file. This file is located in
$ORACLE_HOME/j2ee//config directory.
NOTE:
This is an optional step and is only required if you are using an OC4J instance that is
being managed by the Distributed Component Management (DCM) component that comes with the
full 9iAS release.
In the case of OC4J instances being managed by teh DCM, all configuration changes are maintained
within a central configuration repository and it is necessary to use the "dcmctl updateConfig"
command to propagate configuration changes to the central configuration repository:
For further information on the "dcmctl updateConfig" command line options, see:
Appendix F: DCM Command-Line Utility (dcmctl)
You can download the test Enterprise Archive (EAR) file from the following link:
OracleJmsApp.ear
Save the file as OracleJmsApp.ear.
After downloading the Enterprise Archive file, you will need to deploy it to the
standalone OC4J application server using manual methods.
(e.g $ORACLE_HOME/j2ee/home/applications)
All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter
and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express,
prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.
I have made every effort and taken great care in making sure that the material included on my web site is technically accurate,
but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from
relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.
This article provides a complete working example of how to use
Oracle's Advanced Queuing implementation for JMS (AQ-JMS). We will be
creating a J2EE application that utilizes the Servlet, Message Driven Bean,
and Java Message Service (JMS) API's. Instructions are provided for how to develop,
assemble, configure, and deploy the application to the standalone
version of Oracle Containers for J2EE (OC4J).
Format of the EAR File
Name
Type
INSERT_DT
DATE
ID
NUMBER(4)
The format of the EAR file is as follows:
Download the EAR File
OracleJmsApp(.ear)
|
|- META-INF
| |
| |- application.xml
|
|- OracleJmsEJB(.jar)
| |
| |- META-INF
| | |
| | |- ejb-jar.xml
| | |- orion-ejb-jar.xml
| |
| |- parallelMDBBean.class
|
|- OracleJmsWeb(.war)
|
|-WEB-INF
|
|- web.xml
|- orion-web.xml
|
|- classes
|
|- jobSubmit.class
|- listDataSet
You can download the test Enterprise Archive (EAR) file from the following link:
OracleJmsApp.ear
Pre-requisites
NOTE:
To run the example in this article, you will need the following:
Deployment Process
Now let's take a look at how to deploy our J2EE application. The configuration
changes in this section refer to a standalone OC4J instance. (i.e.
one that is not being managed by the Distributed Component Management (DCM)
component that comes with the full 9iAS release.)
dcmctl updateConfig -ct oc4j -co <OC4J Instance Name>
CONNECT system/manager
CREATE USER aq_admin IDENTIFIED BY aq_admin
DEFAULT TABLESPACE users
TEMPORARY TABLESPACE temp;
ALTER USER aq_admin QUOTA UNLIMITED ON users;
GRANT aq_administrator_role TO aq_admin;
GRANT connect TO aq_admin;
GRANT create type TO aq_admin;
EXECUTE dbms_aqadm.grant_type_access('aq_admin');
CONNECT aq_admin/aq_admin
BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE(
queue_table => 'JMS_TEXT'
, queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE'
, sort_list => ''
, comment => ''
, multiple_consumers => FALSE
, message_grouping => DBMS_AQADM.NONE
, non_repudiation => DBMS_AQADM.NONE
, storage_clause => ''
, compatible => '8.1'
, primary_instance => '0'
, secondary_instance => '0'
);
COMMIT;
END;
/
SHOW ERRORS
BEGIN
DBMS_AQADM.CREATE_QUEUE(
queue_name => 'JOB_QUEUE'
, queue_table => 'JMS_TEXT'
, queue_type => DBMS_AQADM.NORMAL_QUEUE
, max_retries => '5'
, retry_delay => '0'
, retention_time => '0'
, comment => ''
);
COMMIT;
END;
/
SHOW ERRORS
BEGIN
DBMS_AQADM.START_QUEUE('aq_admin.job_queue', TRUE, TRUE);
COMMIT;
END;
/
SHOW ERRORS
(e.g. $ORACLE_HOME/j2ee/home/config/data-sources.xml)
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="aq_admin_o920nt"
location="jdbc/aq_admin_o920nt"
xa-location="jdbc/xa/aq_admin_o920nt"
ejb-location="jdbc/aq_admin_o920nt"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="aq_admin"
password="aq_admin"
url="jdbc:oracle:thin:@bartman:1521:O920NT"
inactivity-timeout="30"
/>
(e.g. $ORACLE_HOME/j2ee/home/config/application.xml)
<resource-provider class="oracle.jms.OjmsContext" name="ojms">
<description>OJMS Context Using a datasource</description>
<property name="url"
value="jdbc:oracle:thin:aq_admin/aq_admin@bartman:1521:O920NT" />
<property name="username" value="aq_admin" />
<property name="password" value="aq_admin" />
</resource-provider>
% dcmctl updateConfig -ct oc4j -co home -v -d
Release 2 (9.0.2)
May 2002
Part No. A92171-02
http://download-west.oracle.com/docs/cd/A97329_03/core.902/a92171.pdf
"Managing Applications", ppF-9
NOTE:
<application name="OracleJmsApp"
path="../applications/OracleJmsApp.ear"
auto-start="true"
/>
<web-app application="OracleJmsApp"
name="OracleJmsWeb"
root="/OracleJms"
/>
Thursday, 17-Aug-2006 12:45:56 EDT
Page Count: 20390