Wednesday, May 23, 2012

OSB and JMS Correlation example

Simple scenario of using OSB as JMS consumer and producer, leveraging correlation.

To begin with, I create the JMS artifacts via the WLS console -

1. Create a new JMS server


2. Create a new JMS module


3. Add a ConnectionFactory and a couple of Queues to the JMS module



Now we have the required JMS artifacts, on to OSB.

Creating the OSB Project

Create a new project in OSB - the scenario in detail. 
OSB proxy service reads an incoming order from the Queue-In. It calls a web service to validate the order. If the order is invalid, then it is written to the Queue-Error. If the order is valid, then it is written to the Queue-Out.

The incoming order is defined as follows -


4.1. Create the project structure


4.2. Import or Create the XSD


4.3. Create the proxy service for the JMS consumer. I have used the Message service  type.


Here I specify that the input will be an element of type OrderData





4.4. Add a Pipeline pair

4.5. Create a Business Service to write to Queue-Out

So what sort of a service do we require here? According to the official docs - If you want to expose one port to clients for a variety of enterprise applications, use Any SOAP or Any XML service types.

For Any SOAP, you must specify if it is SOAP 1.1 or SOAP 1.2. The SOAP service does not have an explicitly defined, concrete interface, i.e. not based on a WSDL.

For Any XML Service, the payload must be a well-formed XML document. The XML Service does not have an explicitly defined, concrete interface.  

N.B. HTTP GET is only supported for messaging services and this service type.
 
We also can use the following -  

Transport Typed Service - Select this option to create a service that uses the EJB, JEJB, or Flow (Split-Join) transport.

Messaging Service - Select this option to create a service that exchanges messages of different content-types. These exchanges can be either request/response or one-way. They can also have a response with no request when used with the HTTP ‘GET’ option for the HTTP transport. Unlike Web Services, the content-type of the request and response need not be the same.

WSDL Web Service - Select this option to create a business service based on a WSDL. (Split-Join) transport.

The 2 that may come immediately into mind are Any SOAP and Any XML.
I chose Any XML and specified the jms transport/Queue-Out etc.


4.6. Amend the proxy service to route to the business service

Test as follows -
Here is a test input file

Here is a Java Class that writes to the Queue-In




 Run and then look at the out Queue in the WLS console


Now add some correlation.

I add the following to the Java client

     textMsg.setJMSCorrelationID("1234");



Now amend the OSB process so that the Business Service can use this correlationID

Add a Transport Header action as follows-
Open the proxy service message flow and add the following to the Route node.





 Save and re-test

  textMsg.setJMSCorrelationID("1234567");

Login to WLS console and look at the Queue-Out


Add a couple of more messages with different correlationIDs.


 Now we need a JMS client to consume the messages based on the correlationID.


Re-visit WLS console -


One of the value adds of specifying the XSD during proxy service definition, is that $body is set accordingly - useful when doing Assigns etc.


  If I had set the Proxy to -

 then $body is -




 I will continue with this process in the next post.

No comments:

Post a Comment