Recent Blog Entries

Thursday, 30 April 2009

Using Oracle JMS Adapter – Part 1: Publish from BPEL to AQ via Partnerlink Invoke

Using the Oracle JMS Adapter is the standard way to inititate asynchronous communication to partner systems, for example JMS-based services, to databases using Oracle AQ or to IBM Websphere MQ.

A complete sample (for SOA Suite 10.1.3.4) demonstrates the steps required for implementing a fire-and-forget (one-way) invoke to an AQ queue on an Oracle database:

1. Create the following datasource and connection pool (in oc4j_soa/config/data-sources.xml)

<managed-data-source name="SensorTestDS" connection-pool-name="SENSOR_CONNECTION_POOL" jndi-name="jdbc/SensorTestDS"/>

<connection-pool name="SENSOR_CONNECTION_POOL">
<connection-factory factory-class="oracle.jdbc.pool.OracleDataSource" user="jmsuser" password="jmsuser" url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=tcp)(HOST=skoser-de.de.oracle.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=DB10G.SKOSER)))"/>
</connection-pool>

(Note: The data source is named “Sensor..” because part 2 shows how to use this from a bpel activity sensor)

2. Enter resource provider in oc4j_soa/config/application.xml:

<resource-provider class="oracle.jms.OjmsContext" name="SendorTestRP">
<description>Sensor JMS/AQ</description>
<property name="datasource" value="jdbc/SensorTestDS"/>
</resource-provider>

The value of the datasource property must match the JNDI lookup (“jndi-name”) of the datasource in data-sources.xml.

3. Create database objects: create a queue named “JMS_OUT” and a queue table “JMS_OUT_TABLE”.

/* Execute as SYS */
CONNECT SYS AS SYSDBA
DROP USER jmsuser CASCADE ;

GRANT connect,resource,AQ_ADMINISTRATOR_ROLE TO jmsuser IDENTIFIED BY jmsuser ;
GRANT execute ON sys.dbms_aqadm TO jmsuser;
GRANT execute ON sys.dbms_aq TO jmsuser;
GRANT execute ON sys.dbms_aqin TO jmsuser;
GRANT execute ON sys.dbms_aqjms TO jmsuser;

connect jmsuser/jmsuser;

begin
sys.dbms_aqadm.create_queue_table(
queue_table => 'JMS_OUT_TABLE',
queue_payload_type => 'SYS.AQ$_JMS_MESSAGE',
sort_list => 'PRIORITY, ENQ_TIME',
compatible => '10.0.0',
primary_instance => 0,
secondary_instance => 0,
storage_clause => 'tablespace users pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited )');
end;
/

begin
sys.dbms_aqadm.create_queue(
queue_name => 'JMS_OUT',
queue_table => 'JMS_OUT_TABLE',
queue_type => sys.dbms_aqadm.normal_queue);
end;
/

begin
dbms_aqadm.start_queue( queue_name =>'JMS_OUT' ,enqueue => true ,dequeue => true );
end;

5. Create a new connection factory entry in JMSAdapter oc4j-ra.xml
(oc4j-soa/application-deployments/default/JMSAdapter/oc4j-ra.xml)

<connector-factory location="eis/Jms/11gAQ" connector-name="Jms Adapter">
<config-property name="connectionFactoryLocation" value="java:comp/resource/SensorTestRP/QueueConnectionFactories/QCF"/>
<config-property name="factoryProperties" value=""/>
<config-property name="acknowledgeMode" value="AUTO_ACKNOWLEDGE"/>
<config-property name="isTopic" value="false"/>
<config-property name="isTransacted" value="false"/>
<config-property name="username" value="jmsuser"/>
<config-property name="password" value="jmsuser"/>
<connection-pooling use="private">
<property name="waitTimeout" value="180" />
<property name="scheme" value="fixed_wait" />
<property name="property-check-interval" value="5" />
<property name="inactivity-timeout-check" value="all" />
<property name="abandoned-connection-timeout" value="20" />
<property name="autoCloseSession" value="" />
<property name="inactivity-timeout" value="120" />
</connection-pooling>
<security-config use="none">
</security-config>
</connector-factory>

The string after “java:comp/resource/” must match the resource provider name in application.xml.

IsTransacted must be set to false for outbound JMSAdapter (see Metalink Note 418884.1 ).

6. Restart oc4j

7. Design a bpel process using the JMS Adapter:

Create a default async bpel process and insert one assign and one invoke activity.

Create a new partnerlink using the “Define Adapter Service” icon:

image

image

Define a db connection to the jmsuser schema:

image

image

image

image

Continue with the Adpater service creation

image

image

image

The Destination Name above must contain

java:comp/resource/SensorTestRP/Queues/JMSUSER.JMS_OUT

We want to publish employees to the queue so copy the addemployees.xsd form here to the BPEL project (in directory bpel) and reference it:

image

The resulting bpel process should look like this:

image

You can download the BPEL Process project for JDeveloper 10.1.3.4 here.

8. Deploy the BPEL process to the default domain.

9. Test the process from the BPEL Console:

image

image

Verify in the database that the message has been written to the JMS_OUT_TABLE:

SQL> select count(*) from JMS_OUT_TABLE;

COUNT(*)
----------
1

Next time, we will cover using sensors with JMS Adapter and then Native MQ Adapter…..

Troubleshooting:

If you receive an Orabpel-12101/ORABPEL-12102 ERRJMS_TRX_COMMIT/ERRJMS_TRX_ROLLBACK then you have not set isTransacted to false for outbound JMS Adapter invocation….

No comments:

Post a Comment