Tuesday, February 23, 2016

Understanding WSO2 ESB Architecture from a Messaging Perspective


I found this diagram from http://supunk.blogspot.com/2009/07/wso2-esb-high-level-architectural.html?view=sidebar. It is very helpful for me to understand how messages work inside ESB.


An application sends a message to the ESB.
The message is picked up by the ESB transport.
Transport sends the message through a message pipe. Quality of service aspects like Security and reliable messaging of the message is taken care in this pipe. Internally this pipe is the in-flow and out-flow of Axis2. ESB can operate in two modes. Message mediation or proxy services. In case of message mediation a single pipe is used. In case of proxy services we can think of separate pipes connecting transport to different proxy services.
Message transformation + routing can be seen as a single unit. As the diagram specifies there is no clear separation between message transformation components and routing components. WSO2 ESB call this the mediation framework. Some transformations happens before routing decision has taken. Some transformations happens after the the routing decision has taken. This part is the Synapse implementation.
After this message is injected to the separate pipes depending on the destinations. Here again quality of service aspects of the messages is determined.
At the end there is a transport layer. This transport layer takes care of the transport protocol transformations required by the ESB. 

How to get response back immediately after WSO2 ESB Proxy Service get the message?

   
I send a message to ESB proxy service, and I would like to get response immediately after the service receive the content and put into the message queue. That means the proxy service will send back response message before it gets processed.

WSO2 ESB provides properties as a way to control different aspects of the messages flowing through the mediation engine. They will not change the content (payload) of the message but they will be used to change the behavior of the message flowing through the ESB.

FORCE_SC_ACCEPTED is the property we could use for this purpose.

FORCE_SC_ACCEPTED

When set to true, this property forces a 202 HTTP response to the client so that it stops waiting for a response.
( 202 HTTP is for the request has been accepted for processing, but the processing has not been completed. )

We can set this property as below.

<property name="FORCE_SC_ACCEPTED" scope="axis2" value="true"/>

This property can be used in scenarios where client send a message to the ESB and ESB will store the message in a persistent store like a message store. In this scenario, client will wait until the timeout if ESB do not send any response. In this kind of scenario, we can use this property and send a 202 Accepted response to the client. Here is an example configuration where ESB store a message in a message store.

  <inSequence>  
    <property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="true"/>  
    <store messageStore="POInbound"/>  
   </inSequence>  


Monday, February 22, 2016

Use WSO2 ESB Developer Studio to Create my first project (2) - Deployment

1. Create Composite Application project
WSO2 DevStudio allows you to package your artifacts into a Composite Application aRchive (CAR) and deploy it to WSO2 servers.

1) Click on Composite Application Project in Developer Studio Dashboard.


 2) Enter composite project name.

 3) Click finish button.


2. Add WSO2 ESB server in Developer Studio

We've installed WSO2 ESB server in my machine. Here we would like to add ESB server to Developer Studio. For detail on how to install WSO2 ESB server, please see my previous blog.

Setup WSO2 ESB server and ActiveMQ server (Part 1) - Installation


Setup WSO2 ESB server and ActiveMQ server (Part 2)


Setup WSO2 ESB server and ActiveMQ server (Part 3) - WSO2 ESB and ActiveMQ connection


1) Click on Add Server - Server in Developer Studio Dashboard.

 
2)  Choose the server type.
3) Click Finish button.

4) Now you can see the WSO2 ESB server showing under servers tab.
 

3. Run Composite application on ESB server.
1) Right click on the composite application name, and choose Export composite Application Project.

2) Enter export destination, then click next button.
 

3) Select artifact to include in the CAR file.
 

4Right click on the composite application, and choose Run As , then Run on Server.
 
5) Choose the server


6) Click on Finish button.

7) Server is running now. We may go to WSO2 ESB server to check if the services created in the developer studio have been deployed to the ESB server.







Thursday, February 18, 2016

Use WSO2 ESB Developer Studio to Create my first project (1) - Installation, Project Setup

1. Go to the following website to download the latest developer studio.
http://wso2.com/products/developer-studio/

2. Install developer studio in my local machine.

3. Click Eclipse I just installed and get into Eclipse.

4. Click on Developer Studio tab, then click Open Dashboard.


5. Click Maven Multi Module project

6. Enter group id and artifact id, then click on finish button.

7.Create ESB project. Click on ESB Config project.



8.  Choose new esb config project.
9. Enter ESB project name, click Finish.

10. Now I would like to create a new proxy service.

11.  Choose create a new proxy service, click on next.


12. Enter the service name, click finish.
13. Now the proxy service xml file is generated and opened in the IDE as below.
From here, we can drag Mediators or Endpoints from left side of palette to the design diagram.



Wednesday, February 17, 2016

How to send xml message through servlet http post?

I want to send an xml file to a service through servlet http post. After I did some research and I found a way to easily do this.

1. I chose to use Apache HttpComponents.

2. Download the latest HttpClient jars from https://hc.apache.org/downloads.cgi

3. In my servlet, I import the following classes.

 import org.apache.http.HttpResponse;  
 import org.apache.http.client.HttpClient;  
 import org.apache.http.client.methods.HttpPost;  
 import org.apache.http.entity.StringEntity;  
 import org.apache.http.impl.client.HttpClientBuilder;  
 import org.apache.http.util.EntityUtils;  

4. In the doPost method, I add the following code.

  // HTTP post xml document to outside service  
           HttpPost post = new HttpPost("https://testserviceurl");  
           post.setHeader("Content-Type", "application/xml");  
           post.setEntity(new StringEntity(xmlString));  
           HttpClient client = HttpClientBuilder.create().build();  
           HttpResponse resp = client.execute(post);  
           String result = EntityUtils.toString(resp.getEntity());  
           System.out.println("post result:" + result);  

HttpClient really provides a simply way to do the job.