Thursday, March 24, 2011

How to use AQ JMS in SOA Suite 11g

I am using the following docs to set up this test case.

Document1

Document2

As per the first document i have created a queue table ,a queue and have started it using following commands

connect / as sysdba;
Grant connect, resource TO jmsuser IDENTIFIED BY jmsuserpwd;
Grant aq_user_role TO 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;



Create queue table

exec DBMS_AQADM.CREATE_QUEUE_TABLE(Queue_table =>'arpit',Queue_payload_type =>'sys.aq$_jms_text_message',multiple_consumers =>false);

create queue

EXEC DBMS_AQADM.CREATE_QUEUE(queue_name =>'ankit',queue_table =>'arpit');

exec DBMS_AQADM.START_QUEUE('ankit');

Now following steps

1>Create a data source to connect to the queue created

log in to Admin console

Go to data sources as indicated and create a new data source.
give it some qunique name such as jdbc/SampleAQJMSDataSource




Provide details for the database you want to connect

Verify the user name and password that you have just created



target it to the soa server



now go to admin console

Services-->Messaging -->JMS module and create a JMS module

Now as per document create a Foreign server in the JMS module

In the foreign server you need to take care of two things

1>JNDI Initial Context Factory: is essentially set to "oracle.jms.AQjmsInitialContextFactory"

2>In the JNDI properties you have to set the jndi for your data source
which should appear like this

datasource=jdbc/SampleAQJMSDataSource

Here jdbc/SampleAQJMSDataSource is the name of the data source i have used in my case to connect to the queues that i have created.

If you will check the document it corresponds to following configuration

<foreign-server>
<initial-context-factory>oracle.jms.AQjmsInitialContextFactory</initial-context-factory>
<jndi-property>
<key>datasource</key>
<value>jdbc/aqjmsds</value>
</jndi-property>
</foreign-server>







Now click on connection factory tab and provide the following details

In the local JNDI -jms/myCF

In Remote JNDI Name:XAQueueConnectionFactory

This is as per the document



Now Further click on Destination tab and create local and remote jndi

The use case and how these works internally has been explained in the document.

Here i am talking only about a working scenario.

So as per document provide some unique local JNDI which server will use to connect to the destination.I have specified it as jms/myQueue

Further in the Remote JNDI name provide the value as Queues/ankit

Here ankit is the name of my queue,you have to replace this with the name of your queue.

Once done save these changes.



Now once you will save the changes it will ask you to restart the server.
Restart the server to make the changes take effect



Now there is one more settings that we need to do which the document doesn't talk about.We need to create an outbound connection pool for JMS adapter to be used in jdeveloper.

So i went to Deployment-->JMS Adapter-->configuration and Outbound connection pool and created an outbound connection pool

eis/SureshQueue as shown in the list



Now once the outbound connection pool is created go to the connection and go to properties tab

In the properteis tab in connection factory location

provide the connection factory that you have created for your foreign server.

The conenctionfactory will be the local JNDI for the connection factory as shown below ==jms/myCF



Save the changes and update your JMS adapter deployment.



Now we will create a simple bpel process to test the functionality of the process.

Just create a simple asynchronous BPEL process



Now drag and drop a JMS adapter in the external reference swinlane and start doing the configuration



select oracle adavanced queuing as option




select produce message beacue we are using it for outbound operation.



search for the queues


NOw pay attenstion in the following configuration

as you can see the Destination name is taking the value which we have specified for local jndi in our destination for foreign server

Further i am using eis/SureshQueue for JMS connection



Use your schema or use opaque schema as per your business need to complete the process.Once process is complete drag a wire from bpel process to the adapter you have created so in all you composite should look like this



Further go to your bpel process and drag a drop an invoke activity and assign activity to copy input variable to the input of invoke activity so your bpel process should look something like this after completion



Now deploy the process and check this

Once you will invoke the process you might get an error like this



Specifically you will get the following error message



Error Message: {http://schemas.oracle.com/bpel/extension}bindingFault
Fault ID default/AQJMS!1.0*soa_3f7f4fbd-e72e-4fdd-9820-16e30daab15c/BPELProcess1/80011-BpInv0-BpSeq0.3-3
Fault Time Mar 25, 2011 1:03:34 PM
Non Recoverable System Fault :
<bpelFault><faultType>0</faultType><bindingFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="summary"><summary>Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'Produce_Message' failed due to: [Connector:199175]This ManagedConnection is managed by container for its transactional behavior and has been enlisted to JTA transaction by container; application/adapter must not call the local transaction begin/commit/rollback API. Reject event LOCAL_TRANSACTION_STARTED from adapter.". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution. </summary></part><part name="detail"><detail>[Connector:199175]This ManagedConnection is managed by container for its transactional behavior and has been enlisted to JTA transaction by container; application/adapter must not call the local transaction begin/commit/rollback API. Reject event LOCAL_TRANSACTION_STARTED from adapter.</detail></part><part name="code"><code>null</code></part></bindingFault></bpelFault>




Error Message:
Fault ID reference:40011
Fault Time Mar 25, 2011 1:03:34 PM
Non Recoverable System Fault :
Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'Produce_Message' failed due to: [Connector:199175]This ManagedConnection is managed by container for its transactional behavior and has been enlisted to JTA transaction by container; application/adapter must not call the local transaction begin/commit/rollback API. Reject event LOCAL_TRANSACTION_STARTED from adapter.". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.


It took me a long time to resolve this issue.

By default when you are configuring the process from jdeveloper

a default outbound connection pool is used that is

eis/aqjms/Queue

YOu have to use only this one.

So Just go to your admin console

Go to Deployment-->JMS Adapter

Configuration_>Outbound connection pool and click on eis/aqjms/Queue

Go to properties tab and in the connection factory location specify the local jndi of the connection factory that you have created,which in our case is jms/myCF

Now update your JMS Adapter and change the jndi name in your Jdeveloper also.

Redeploy the process and test it again.

This time it should work fine.


now you can log in to database with the user and password and do a query on the table to know if the process completed successfully or not.In my case i have called it twice so i am getting a count of 2.

No comments: