Overview
* Download how-to-connect-to-oemsjmsd.zip
* Start JDev (10.1.3.3.0)
* Setup AQ
* Create Resource Adapter
* Create EAR and deploy EAR
* Test with a client
Setup AQ
* Create MyAQUser.sql as follows:
DROP USER MyAQUser CASCADE; GRANT CONNECT, resource,AQ_ADMINISTRATOR_ROLE TO MyAQUser IDENTIFIED BY MyAQUserPass; GRANT EXECUTE ON sys.dbms_aqadm TO MyAQUser; GRANT EXECUTE ON sys.dbms_aq TO MyAQUser; GRANT EXECUTE ON sys.dbms_aqin TO MyAQUser; GRANT EXECUTE ON sys.dbms_aqjms TO MyAQUser; CONNECT MyAQUser/MyAQUserPass; -- Create table to hold the queue, then create queue. -- For topics multiple_consumers must be true BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( Queue_table => 'QTab', Queue_payload_type => 'SYS.AQ$_JMS_MESSAGE', sort_list => 'PRIORITY,ENQ_TIME', multiple_consumers => FALSE, compatible => '8.1.5'); DBMS_AQADM.CREATE_QUEUE( Queue_name => 'MY_QUEUE', Queue_table => 'QTab'); DBMS_AQADM.START_QUEUE( queue_name => 'MY_QUEUE'); DBMS_AQADM.CREATE_QUEUE_TABLE( Queue_table => 'TTab', Queue_payload_type => 'SYS.AQ$_JMS_MESSAGE', sort_list => 'PRIORITY,ENQ_TIME', multiple_consumers => TRUE, compatible => '8.1.5'); DBMS_AQADM.CREATE_QUEUE( Queue_name => 'MY_TOPIC', Queue_table => 'TTab'); DBMS_AQADM.START_QUEUE( queue_name => 'MY_TOPIC'); END; /
* Connect sys as sysdba
* @MyAQUser.sql
Resource Adapter
Overview
* Create an application called ‘MyAQTest’
* Create an empty project called ‘MyAQRA’
* Create ra.xml
* Create oc4j-ra.xml
* Rebuild all
ra.xml
* Right click project: New -> Deployment Profiles -> RAR File
* Deployment Profile Name: MyAQRA
* Replace ra.xml content with one from howto
* Globally replace:
‘OEMSJMSDRADisplayName’ with ‘My AQ JMS Resource Adapter’
‘OEMSJMSDReference’ with ‘MyAQJMSResourceProvider’
‘MY_QUEUE’ if a different queue name is used in ‘Setup AQ’ section.
‘MY_TOPIC’ if a different queue name is used in ‘Setup AQ’ section.
oc4j-ra.xml
* Right click project: New -> Deployment Descriptor -> OC4J Deployment Descriptor Wizard -> oc4j-ra.xml
* Replace content with that of howto
* Globally replace:
‘OEMSJMSDRAInstanceName’ with ‘MyAQConnector’
‘OEMSJMSDRASubcontext’ with ‘MyAQJMSCtx’
‘OEMSJMSDReference’ with ‘MyAQJMSResourceProvider’
EAR Project
Overview
* Create an empty project called ‘MyAQEAR’
* Create ‘data-sources.xml’
* Create ‘orion-application.xml’
* Create ‘oc4j-connectors.xml’
* Create a new Deployment Profile of EAR File type. Name it ‘MyAQEAR’
data-sources.xml
* Right click project: New -> Deployment Descriptor -> OC4J Deployment Descriptor Wizard -> data-sources.xml
* Replace content with that of howto
* Move all proxy-interface elements inside connection-factory element.
* Globally replace:
‘MyChannelDemoDataSourcePool’ to ‘MyAQUserDSPool’
‘MyChannelDemoDataSource’ to ‘MyAQUserDS’
‘oemsjmsdthin’ to ‘MyAQUserDS’
‘MyChannelDemoUser’ to ‘MyAQUser’
‘MyChannelDemoPassword’ to ‘MyAQUserPass’
* Set url accordingly: ‘jdbc:oracle:thin:@localhost:1521:orcl’
orion-application.xml
* Right click project: New -> Deployment Descriptor -> OC4J Deployment Descriptor Wizard -> orion-application.xml
* Replace content with that of howto
* Globally replace:
‘OEMSJMSDReference’ with ‘MyAQJMSResourceProvider’
‘MyChannelDemoDataSource’ to ‘MyAQUserDS’
oc4j-connectors.xml
* Right click project: New -> Deployment Descriptor -> OC4J Deployment Descriptor Wizard -> oc4j-connectors.xml
* Replace content with that of howto
* Globally replace:
‘OEMSJMSDRAInstanceName’ with ‘MyAQConnector’
‘OEMSJMSDRASubcontext’ with ‘MyAQJMSCtx’
‘OEMSJMSDRADeploy’ to ‘MyAQRA’
‘OEMSJMSDReference’ with ‘MyAQJMSResourceProvider’
‘MY_QUEUE’ if a different queue name is used in ‘Setup AQ’ section.
‘MY_TOPIC’ if a different queue name is used in ‘Setup AQ’ section.
Deployment Profile
* Click Rebuild All button
* Create a new Deployment Profile of EAR File type. Name it ‘MyAQJMSResourceAdatper’
* Select MyAQRA.deploy in Application Assembly screen.
* Create a new File Group named ‘FG1’ of Packaging type.
* click File Groups -> FG1 -> Filters
* Select ‘oc4j-connectors.xml’ only.
Deploy EAR
* Right click MyAQJMSResourceAdatper.deploy
* Click Deploy to LocalApplicationServer
Test Client
* Create a new Java Application Project called ‘MyAQJMSClient’
* Add to project class path
C:\prog\oracle\product\10.1.3.1\OracleAS_1\lib\dms.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\jdbc\lib\ojdbc14.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\jazn.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\oc4j.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\oc4jclient.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\lib\adminclient.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\lib\bcel.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\lib\connector.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\lib\javax77.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\lib\jms.jar
C:\prog\oracle\product\10.1.3.1\OracleAS_1\j2ee\home\lib\oc4j-internal.jar
* Create a new Java Class named ‘AbstractJMSClient’: New -> General -> Java Class
package myaqjmsclient; import javax.jms.*; import javax.naming.*; public class AbstractJMSClient { private static final String CONN_FACTORY = "java:comp/env/jms/QueueConnectionFactory"; private static final String HELLO_Q = "java:comp/env/jms/helloQueue"; private QueueConnectionFactory factory = null; protected Queue getQueue() throws NamingException { Context ctx = new InitialContext(); QueueConnectionFactory factory = getQueueConnectionFactory(); Queue q = (Queue) ctx.lookup(HELLO_Q); return q; } protected QueueConnection getQueueConnection() throws NamingException, JMSException { return getQueueConnectionFactory().createQueueConnection(); } private QueueConnectionFactory getQueueConnectionFactory() throws NamingException { Context ctx = new InitialContext(); factory = (QueueConnectionFactory) ctx.lookup(CONN_FACTORY); return factory; } }
* Create a new Java Class named ‘SendHelloAQ’: New -> General -> Java Class -> Extends ‘myaqjmsclient.AbstractJMSClient’ and check ‘Generate Main Method’
package myaqjmsclient; import javax.jms.*; import javax.naming.NamingException; public class SendHelloAQ extends AbstractJMSClient { public static void main(String[] args) throws Exception { SendHelloAQ sendHelloAQ = new SendHelloAQ(); sendHelloAQ.send(); } public void send() throws JMSException, NamingException { Queue q = getQueue(); QueueConnection connection = getQueueConnection(); connection.start(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender(q); TextMessage msg = session.createTextMessage(); msg.setText("Hello AQ!"); sender.send(msg); sender.close(); session.close(); connection.close(); System.out.println("Message Sent"); } }
* Create a new Java Class named ‘ReceiveHelloAQ’: New -> General -> Java Class -> Extends ‘myaqjmsclient.AbstractJMSClient’ and check ‘Generate Main Method’
package myaqjmsclient; import javax.jms.*; import javax.naming.NamingException; public class ReceiveHelloAQ extends AbstractJMSClient { public static void main(String[] args) throws Exception { ReceiveHelloAQ receiveHelloAQ = new ReceiveHelloAQ(); receiveHelloAQ.receive(); } public void receive() throws NamingException, JMSException { Queue q = getQueue(); QueueConnection connection = getQueueConnection(); connection.start(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueReceiver receiver = session.createReceiver(q); TextMessage msg = (TextMessage)receiver.receiveNoWait(); if(msg != null) System.out.println("Received: " + msg.getText()); else System.out.println("No message received"); receiver.close(); session.close(); connection.close(); } }
* Create a new file named ‘jndi.properties’
java.naming.factory.initial=com.evermind.server.ApplicationClientInitialContextFactory
java.naming.provider.url=ormi://localhost:12401/MyAQJMSResourceAdatper
# Or use opmn:ormi for automatic port determination
#java.naming.provider.url=opmn:ormi://localhost/MyAQJMSResourceAdatper:home
java.naming.security.principal=oc4jadmin
java.naming.security.credentials=welcome1
* Create a new ‘application-client.xml’: New -> Deployment Profiles -> Client JAR File -> Profile Name: MyAQJMSClient
<?xml version = '1.0' encoding = 'windows-1252'?> <application-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee"> <display-name>MyAQJMSClient-app-client</display-name> <resource-ref> <res-ref-name>jms/QueueConnectionFactory</res-ref-name> <res-type>javax.jms.QueueConnectionFactory</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <resource-env-ref> <resource-env-ref-name>jms/helloQueue</resource-env-ref-name> <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type> </resource-env-ref> </application-client>
* Create a new ‘orion-application-client.xml’: New -> Deployment Descriptors -> OC4J Deployment Descriptor Wizard -> orion-application-client.xml -> Version 10.0
<?xml version = '1.0' encoding = 'windows-1252'?> <orion-application-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-application-client-10_0.xsd"> <resource-ref-mapping name="jms/QueueConnectionFactory" location="MyAQJMSCtx/MyQCF"/> <resource-env-ref-mapping name="jms/helloQueue" location="MyAQJMSCtx/MyQ"/> <!-- location="MyAQJMSCtx/Topics/Topics/MY_QUEUE" --> </orion-application-client>
* Run ‘SendHelloAQ.java’ to send a message.
set ORA_AS_HOME=C:\prog\oracle\product\10.1.3.1\OracleAS_1 set JAVA_HOME=%ORA_AS_HOME%\jdk set MY_CP=.;%ORA_AS_HOME%\lib\dms.jar;%ORA_AS_HOME%\jdbc\lib\ojdbc14.jar;%ORA_AS_HOME%\j2ee\home\jazn.jar;%ORA_AS_HOME%\j2ee\home\oc4j.jar;%ORA_AS_HOME%\j2ee\home\oc4jclient.jar;%ORA_AS_HOME%\j2ee\home\lib\adminclient.jar;%ORA_AS_HOME%\j2ee\home\lib\bcel.jar;%ORA_AS_HOME%\j2ee\home\lib\connector.jar;%ORA_AS_HOME%\j2ee\home\lib\javax77.jar;%ORA_AS_HOME%\j2ee\home\lib\jms.jar;%ORA_AS_HOME%\j2ee\home\lib\oc4j-internal.jar %JAVA_HOME%/bin/java -cp %MY_CP% myaqjmsclient.SendHelloAQ
* Run ‘ReceiveHelloAQ.java’ to receive a message.
set ORA_AS_HOME=C:\prog\oracle\product\10.1.3.1\OracleAS_1 set JAVA_HOME=%ORA_AS_HOME%\jdk set MY_CP=.;%ORA_AS_HOME%\lib\dms.jar;%ORA_AS_HOME%\jdbc\lib\ojdbc14.jar;%ORA_AS_HOME%\j2ee\home\jazn.jar;%ORA_AS_HOME%\j2ee\home\oc4j.jar;%ORA_AS_HOME%\j2ee\home\oc4jclient.jar;%ORA_AS_HOME%\j2ee\home\lib\adminclient.jar;%ORA_AS_HOME%\j2ee\home\lib\bcel.jar;%ORA_AS_HOME%\j2ee\home\lib\connector.jar;%ORA_AS_HOME%\j2ee\home\lib\javax77.jar;%ORA_AS_HOME%\j2ee\home\lib\jms.jar;%ORA_AS_HOME%\j2ee\home\lib\oc4j-internal.jar %JAVA_HOME%/bin/java -cp %MY_CP% myaqjmsclient.ReceiveHelloAQ
References
* http://blogs.oracle.com/olaf/2007/07/oc4j_configuring_and_using_aq.html
* http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/how-to-connect-to-oemsjmsd/doc/how-to-connect-to-oemsjmsd.html
* http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html
* http://mike-lehmann.blogspot.com/2006/09/simple-mdb-with-oracle-database-jms.html