Saturday, April 6, 2013

ESB , JMS Masala Recipe using WSO2 ESB and ActiveMQ..


Message oriented middleware (MOM) is one of the essential part of when it comes to building a SOA based solutions.There are number of MOMs out there. Integrating most of them for special use cases some what tricky. Today in this blog post we are going to simulate below scenario using WSO2 ESB and Active MQ as the JMS broker.


Proxy service that takes JSON parameters and return JSON output.( REST POST on this proxy in order to receive an JSON response from proxy).
Inside the proxy service it should transform received JSON into XML and put in in OUT queue(On Active MQ).
Then Proxy continue and listen on IN queue for message with correlation id of message that it just put into OUT queue.
Some third party application taking the messages from OUT queue and after doing its own operation on message put the message in the IN queue back. 
Once proxy gets message to IN queue it transforms from XML to JSON and returns as result.
In the big picture, We called REST web service by posting some JSON and received back some JSON. Internally web service have converted JSON to XML, posted it to OUT queue waited for a message with same correlation id on IN queue, transformed message to JSON and returned it as result of proxy call.

Step-1 : Setting up the environment.
To set up the environment please follow the below steps.
1. Open axis.xml which located in $ESB_HOME/repository/conf/axis2
2. Go to Transport Ins (Listeners) section.
   Uncomment the transportReceiver appropriate for JMS environment of your set up (for this sample we have used ActiveMQ)
3. Go to Transport Outs (Senders) section.
   Uncomment the JMS transportSender.
4. Then put the client JARs for your JMS server in Carbon classpath. In case of Apache ActiveMQ, you need to put the following JARs in the classpath:
   The required dependencies are in the $ACTIVEMQ_HOME/lib directory. You need to copy these JAR files over to $ESB_HOME/repository/components/lib directory.

Figure 1.1 shows the out use case as a model
                                                                                      Figure 1.1

*For the simulation of the scenario we can use another proxy service as the third party application. It will take the XML messages form the OUT queue put it in the IN queue.
Step-2 : Implementation.

1. Proxy that takes JSON parameters of REST API call and transforms REST call parameters and put's them as XML message into ActiveMQ "OUT" queue.
    And wait for some other application to put the same message (matched by correlation id ) in to "OUT" (this is configured by passing "transport.jms.ReplyDestination=IN" JMS parameter via URL.)

contentType text/xml

2. Proxy that simulate the third party application which take the message from OUT and put them in to IN.
    (This proxy will listen to OUT and when some message come in to OUT it will pick it and put it in the IN queue.)


contentType application/xml myQueueConnectionFactory dynamicQueues/OUT

Ultimately this sample will see by the outer world ,proxy service that takes JSON parameters and return JSON parameters

No comments:

Post a Comment