Showing posts with label JMS. Show all posts
Showing posts with label JMS. Show all posts

Sunday, July 21, 2013

Retry and Rollback using DB adapter - SOA Suite 11G

Hi All,

Retrying and rolling back transactions that got failed while invocation is one of the major things that needs to be keep in mind while designing the solution for any interface.As it helps in preventing any data discrepancy that can be there between source and target systems,had there not been any rollback in case of failed transaction.

I will be demonstrating,how to retry and rollback failed transactions in SOA.To illustrate this use case I will be using one JMS queue from where our composite will consume the message and, after that it will insert data in 3 tables that I have created for this usecase.you will be requiring XA JNDIs both for Database and JMS Adapters.

Three tables have been created namely Customer,Order, and Invoice.Our SOA process will insert records in table in the same order.


On weblogic console,we need to set some properties for our jms queue for retry functionality.Just go to your jms queue and navigate to "Delivery Failure" tab for your queue.Set following parameters
  • Redilvery Delay Override: 10000 (10 seconds) It is the interval after which rolledback messages will be retried.
  • Redilvery Limit: 2 (Number of times failed message will be retried).
  • Expiration Policy: Redirect (or Discard, if you want to discard the message after retry) Redirect will move the message to "Error Destination" if even after configured retry parameters message is failed.
  • Error Destination: <Queue Name> Queue to which failed message will be moved after all retry attempts.
In the BPEL process, add catch or catch all handler for your composite to handle any faults that may occur.In the Catch All block ,explicitly throw a rollback fault using throw activity.It will rollback the complete transaction i.e. undo all the data inserted in any of the tables and then request message will be rolled back to the jms queue.

NOTE: Any fault thrown using throw activity that is not being caught will result in rollback of complete transaction.


Now,first we will test the happy path.Deploy your code to EM and test the interface.Records will be inserted into all the tables successfully.
To see how rollback works,I will intentionally change the DB jndi for Invoice adapter.To do that open jca file for your Invoice DB Adapter and give some random value in that.Save and redeploy the code.Now the interface will fail while inserting the data in Invoice table and flow will got to Catch All block,where transaction will be rollbacked.
To validate this,check the tables and no new records would have been inserted into the tables.

Since we have configured,retry parameters for our request queue, the rollbacked message will be retried again after 10 seconds.Message state will be changed to "delayed" which means it is being retried.

After all failed attempts the message will be redirected into the error destination that we have configured for our queue.


In this way, you can implement retry and rollback functionality in your interfaces.
Hope this helps you.


Happy Learning,
Cheers !!!

Thursday, June 20, 2013

Getting and Setting JMS Header Properties - SOA 11G

Hi Guys,

Sometimes there is requirement where you are required to set some JMS header values and then send the jms message to the client or consumer may interact with you via jms queue and sends some user defined properties in the JMS header.In BPEL 11G, we can easily set or retreive these values.

Setting JMS Header Values


Step1: Click on the invoke activity inside your BPEL process that is calling your JMS adapter for publishing messages in the jms queue.Then click on the source tab of BPEL.
Step2: Inside the invoke activity code add this property <bpelx:inputProperty name="jca.jms.JMSProperty.propertyname" variable="variablename"/>
where propertyname: name of the property you want to set and variablename: variable from which you are passing value to this property.For instance,in out usecase I am setting following properties:

      <bpelx:inputProperty name="jca.jms.JMSProperty.MSG_ID" variable="TransID"/>
      <bpelx:inputProperty name="jca.jms.JMSProperty.FROM_SYSTEM" variable="FROM_SYSTEM"/>   
      <bpelx:inputProperty name="jca.jms.JMSProperty.ServiceName" variable="ServiceName"/>

Make sure you populate all these properties before calling invoke activity,otherwise these properties will contain null/blank values.

Step3: Deploy and test your code.Verify that these values are getting set by looking into the flow trace of your composite.
Step4: Also,you can verify the message in jms queue as well and see if the properties are properly set or not.

Getting JMS Header Values


Step5:Inside your BPEL process,click on the receive activity that is receiving input from the jms adapter and click on source.

Step6: Add this property inside your receive activity: <bpelx:outputProperty name="jca.jms.JMSProperty.propertyname" variable="variablename"/>. It is same as we did for setting the property except the outputProperty tag.In my example, I am retreiving the value of jms header that I set previously.

      <bpelx:outputProperty name="jca.jms.JMSProperty.MSG_ID" variable="TransID"/>
      <bpelx:outputProperty name="jca.jms.JMSProperty.FROM_SYSTEM" variable="FROM_SYSTEM"/>   
      <bpelx:outputProperty name="jca.jms.JMSProperty.ServiceName" variable="ServiceName"/>

     
Create the variables that will store the values of these properties.

Step7: Deploy your code and test your composite.Inside flow trace verify you are able to retreive the jms properties headers value from the JMS message.
In this way you guys can set and get the header properties of any JMS message in SOA 11G.Apart from accessing these values from BPEL,you can also access these values from Mediator.In mediator, they are accessed in the assign step using:

Inbound: $in.property.jca.jms.JMSProperty.<propertyname>
Outbound: $out.property.jca.jms.JMSProperty.<propertyname>

Hope this post of some help to you.

Happy Learning,
Cheers !!!


Thursday, April 11, 2013

Deployment using JDeveloper

Hi Guys,

Hope you liked my last post desribing how to configure and work with JMS adapter.In this post I am going to show you how to deploy any SOA composite from JDeveloper to Enterprise Manager Console(EM). Though, this has been covered in my last two posts as a part of complete tutorial.Still for all those who dont want to go through the complete post.Here's stet by step instructions to deploy your SOA Composite.

Prerequisite for this tutorial

1. Oracle JDeveloper
2. Weblogic Server up and running

I have done this tutorial using JDeveloper 11.1.1.6.0 and Weblogic Server 10.3.6.0. Deployment from JDev for 11G versions is same for all.

1. Open up JDev and any recent project that you have completed.Right click on the project and select Deploy --> "your composite name".
2. Deployment window will pop up asking you to whether you want to deploy this composite to an application server or you want to compile your project and create its SAR (SOA Archive) file.Select "Deploy to Application Server",since we are deploying it to EM and click next.

3.Deployment configuration window will come up.
  • It will show your project name, current revision ID and New Revision ID(change it,if you want to deploy your project with new revision ID other than current ID). 
  • Check mark the "Mark composite revision as default" if you want this version of your composite to be active and start receiving requests,otherwise uncheck it.
  • If you are not changing your revision ID and redploying with same revision ID check mark "Overwrite any existing composites with same revision ID". SOA configuration plan lets you deploy your composite by choosing configuration plan. Will publish separate post explaining the concept of SOA Config Plans.Click next. 


4. In the next window choose the application server you wish to deploy your composite on. If you havenot created your application server yet or dont know how to create app server connection GO HERE. You can have separate application server connections depending upon your environment such as test, dev, pre prod and prod. Choose the appropriate one and click next.



5. In this window you need to select the partition on which you want your application to be deployed.There can be number of partitions on EM console. Select the partition which you want to use , we are using "default" in our case.Click next.


6.Final window will give you deployment summary showing all the details that you selected in previous steps.Cross check and verify.Click finish to start the deployment.


7. Examine the deployment logs in JDev during deployment and verify composite has been successfully deployed.In case of any exception while deployment proper error will be logged in deployment logs.



8.Open up your Enterprise Manager(EM) and log in.After logging in drill down to the partition you deployed your composite and verify its there.

Thats it now your composite is active and accepting requests.Hope you got all the steps.Apart from this method of deployment there are other methods of deployment as well such as deploying directly through EM or deploying using ANT scripts. In forthcoming posts will explain those as well.

Stay tuned in.......
Happy Learning

Cheers,

Oracle JMS Adapter Tutorial

Hi Guys,

Today we will learn the concept of JMS adapter in SOA Suite.Oracle JCA Adapter for JMS (Oracle JMS Adapter), enables an Oracle BPEL process or an Oracle Mediator component to interact with JMS.While working with JMS adapter we can use either topics or queues.

Messages are exchanged through a queue via point to point interaction wheres as in topics the publish-subscribe model is being used i.e messages are sent to a topic and can be read by many subscribed clients.We will implement one usecase scenario in which our BPEL process will pick message from one jms queue and the same message will be published in another JMS queue.This scenario will demonstrate how to consume and publish messages in jms queue.Ofcourse, our queues would be present on weblogic application server.Also,knowledge about queues and connection factory by viewers is preasumed.

Before we start below are some prerequisites in order to implement this usecase:

1. Oracle JDeveloper 11G
2. Oracle SOA Suite  11G
3. Weblogic Server Up and running

I have done this tutorial using Oracle Soa Suite 11.1.1.6.0 , JDeveloper 11.1.1.6.0 and Weblogic Server 10.3.6.0.

Consume Message : The Consume Message option enables the adapter to consume (receive) inbound messages from a JMS destination.
Produce Message : enables the adapter to produce (send) outbound messages for a JMS destination.
Request/Reply   : Oracle JMS Adapter supports both synchronous and asynchronous request reply interaction pattern.It is out of context from our tutorial perspective.


Lets start with the tutorial

1. We will use the same application "SOALabs" for this(refer Hello World BPEL Process) and create a new project in this application.First of all go to Files --> New. Then navigate to Projects under categories on left hand side and select SOA Project and click OK.





















2. Window will ask you for project name.Give the project name as JMSLab and click next.


















3. Select "Empty Composite" as composite template and finish.


















4. Payload will be published in a JMS queue in a specific format.That format we will design using XML Schemas(XSD).For our application we will be using same schema both for consuming message from jms queue as well as producing message onto jms queue.Right click on xsd folder under project navigator and click New.




5. Select XML Schema as the item and click OK.

















6. Window will come up asking for name.Enter Employee.xsd under File Name and click OK.Copy and paste below code snippet in your xsd file and save it.
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://xmlns.example.com/EmployeeDetails"
            targetNamespace="http://xmlns.example.com/EmployeeDetails"
            elementFormDefault="qualified">
    <xsd:element name="EmployeeDetailsRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="EmployeeDetailsRequestType"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="EmployeeDetailsRequestType">
        <xsd:complexType>
            <xsd:sequence>
    <xsd:element name="Name" type="xsd:string" minOccurs="0"/>
    <xsd:element name="Designation" type="xsd:string" minOccurs="0"/>
    <xsd:element name="Address" type="xsd:string" minOccurs="0"/>
    <xsd:element name="Department" type="xsd:string" minOccurs="0"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>
 






















7.Your schema will look something like this.

8.Now we will create two jms adapters one for consuming message and other for producing the jms message.Drag and drop JMS Adapetr from component pallette on exposed services lane.

9. JMS adapter config wizard will open up.Click next.




10. Give "ConsumeMessage" as service name and click next.

11. In the next window we have to select JMS provider. Its weblogic server in our case so slect the same and move further.

 12. Next we have to select the application server connection where our JMS queue is residing. If you dnt know how to create application server connection click Here: 

 13. Next window we need to define the adapter interface.We will be using the XSD that we created earlier for our purpose.So leave it as it is and move next.
 14. Since we are consuming message from jms queue select consume message as operation type and click next.
 15. Next window we are expected to mention destination name(queue in our case) and JNDI name for connecting to our destnation.
 16.Click on Browse button next to Destination Name to select our queue. Under jms module select "RequestQueue" and click ok.

 17.In the JNDI name mention the JNDI of our outbound connection pool that resides on Weblogic server Console.To check the JNDI name login to weblogic console and click on Deploymenys --> JMS Adapter --> Configuration --> Outbound Connection Pools --> Expand "oracle.tip.adapter.jms.IJmsConnectionFactory" and check your JNDI in our case its "eis/wls/Queue".
 18. Click next and in this window we will specify the schema for the format in which our composite will expect the input paylaod.Click on torch button and browse for Schema.
  
19. Drill down to Employee.xsd and select EmployeeDetailsRequest as element and click ok.
 

 20. Click Next and finish.
 
 21. In the same way drag and drop one more jms adapter to External References lane this time.

 22. Provide service name.
 23. Follow steps 11 to 13 again for next 3 windows that will come up.Next window will be prompting for Operation Name.This time select Produce Message and click next.
 25. In the same fashion like we did for our inbound jms adapter, select the queue name (ResponseQueue in this case) and JNDI.Click next.
 
 26. Again select the same schema --> EmployeeDetailsRequest then next and finish.
 
 27. Now Drag and drop BPEL process from component pallette under components section in composite.xml.Window will pop up for creating BPEL process.Change the name of BPEL process to "BPELProcess" and select template as "Define Interface Later".Leave rest of the settings as default.Click OK.
 
 28. We have configured two jms adapters and one BPEL process uptill now and the resulting composite will look like this.

 29. Now, we will wire both the jms adapters with our BPEL process. Just drag the right arrow from ConsumeMessage adapter and drop it onto BPEL process.

 30. In the same fashion drag the left arrow from ProduceMessage adapter and drop it onto BPEL process.
31. Our composite will look like this.Save all.
 32. Lets start with the coding part now.Double click the BPEL process.BPEL design will be empty.Now drop receive activity from components pallette between two circles as shown in the screenshot.
  34. After that wire the receive activity to partner link to its left i.e consume message.
 
 35.Pop up will show up to edit the receive activity.Change its name to ReceiveInput and click on "+" sign next to Variable tag.
36.Create variable window will pop up.Leave the default name and click OK.



37.This  variable will recieve the input from the inboun jms adapter and the created variable is of that adapters type only.Make sure you "check" the create instance section.It is required to instantiate our BPEL process when we will test it.Cleick OK.


38. Drag and drop invoke activity after receive activity in BPEL designer.Invoke activity enables you to specify an operation you want to invoke for the service (identified by its partner link). The operation can be one-way or request-response on a port provided by the service. You can also automatically create variables in an invoke activity.


39.Wire it to the partne link on the right side.


40. Window will open up for editing invoke activity.Same way we did for receive rename it and create the input variable.



41. Invoke activity will appear like this after ceration of input variable.This variable will be hold the output message payload and will publish its content in response jms queue.


42. So far so good.Our BPEL code will look like this.


43. Now we need to populate the input variable of the invoke activity by using the input paylaod.Assing activity will be used for this purpose.Drag and drop one assign activity between recieve and invoke activity.



44. Double click assign and expand receiveinput variable on the left side and the invoke input variable on the right side.Map name on the left side to the name on the right side.





45. Similarly map all other remining elements from left hand side to right hand side one to one.Final Assing activity will look like this.Click Ok.


47. Save all and our BPEL will look like this.





48. Its time for evaluation of our efforts guys that we had put in so far.Lets deploy our baby and test it.Right click JMS Labs --> Deploy --> JMSLab.





49. I assume you guys have gone through "Hello World BPEL process" so will leave the explanation part of each module.select Deploy to application server click next.




50. Next.
51. Select your application server and click next.
52. Select the partition and its default in our case click FINISH.


53. Make sure our composite is successfully deployed by examing the Deployment logs in JDev.



54. Time to test our SOA composite.Remember we have designed our composite that will consume message from one jms queue and publish it to respone jms queue.Now we will publish one sample jms message in our RequetQueue for testing our composite.Login to weblogic server console.


 55. Under JMS Modules.Scan down to "RequestQueue" and click it open.

 56. Click on monitoring tab once queue opens up.Notice the numbers under "Consumers Current". If its more than 1 (2 in our case) means our composite is deployed fine and is expecting messages on this requet queue.Guys dont get confused here by looking at 2 queue.It all depends how many managed servers your cluster have.If you have 2 managed servers 2 queues will show here 3 for 3 and so on.Just chill and concentrate on our testing part.

 57. Click on the one of the queue and click show messages.

 58. Click NEW tab to create new message in this queue.

 59. Copy and paste below sample XML in text box and press OK.

<?xml version="1.0" encoding="UTF-8" ?>
<ns1:EmployeeDetailsRequest xmlns:ns1="http://xmlns.example.com/EmployeeDetails">
  <ns1:EmployeeDetailsRequestType>
    <ns1:Name>Karan</ns1:Name>
    <ns1:Designation>Software Engineer</ns1:Designation>
    <ns1:Address>India</ns1:Address>
    <ns1:Department>IT</ns1:Department>
  </ns1:EmployeeDetailsRequestType>
</ns1:EmployeeDetailsRequest>


 60. You will see JMSmessage sent successfully.

 61. Now open up EM and drill down to default partition under SOA tab and click on oyr composite JMSLab.You will see one instance created over there.Click on instance ID to check the flow trace.
 
 62. In flow trace click on BPELProcess to open up the message flow.

 63. Message has been successfully picked and published to response JMS queue.

 64. Now go back to weblogic console and open up ResponseQueue to check if message is there or not.

 65. Click Show messages and Click on ID tab in the table.


 Bingo !!!its our message there.Message has been successfully published in the response queue.Pheeewwwww that was so tedious work but as long as result is fruitful, shouldn't bother you.So Guys today we learnt how to use the consume and produce operations of a JMS adapter.I hope that you guys are able to understand as i tried to cover all the steps and tried to implement it with precision.Still any doubts ,post it in here or mail it to me.

Ill be more than happy to help you.Stay tuned in for my next blog.

Cheers,