Service Chaining

Exclusive offer: get 50% off this eBook here
Enterprise Integration with WSO2 ESB

Enterprise Integration with WSO2 ESB — Save 50%

Over 15 recipes to calibrate seamless modularity to SOA and address commonly-faced enterprise integration challenges with a zero-code approach with this book and ebook

$20.99    $10.50
by Prabath Siriwardena | October 2013 | Open Source

This article by Prabath Siriwardena, the author of Enterprise Integration with WSO2 ESB, helps you gain knowledge about Service Chaining. The Enterprise Service Bus(ESB) today serves as a key component in most of the enterprise grade deployments. In most cases the ESB removes point-to-point dependencies in your system to build a highly scalable and loosely coupled solution. But that does not necessarily mean ESB means SOA. ESB is a key ingredient to build an SOA infrastructure, but it's not a must. Even with an ESB if not followed industry best practices and patterns you will end up with a mess.

(For more resources related to this topic, see here.)

Service Chaining is one of the common and popular use case for an ESB to support. To cater for a request from the client, the ESB may have to call a chain of business services. This is different from the Scatter and Gather pattern we covered before. The Scatter and Gather EIP explains how to handle a scenario where the incoming request has to be handled by multiple recipients and each recipient will reply back to form an aggregated response. Service Chaining does more intelligent decision making and simply does which is very much similar to service orchestration.

Getting ready

Let's take TravelManagementService as an example. To cater a travel arrangement request from the client, TravelManagementService has to call AirLineReservationService with the provided dates for travelling. If that succeeds it will call RentACarService and finally it will call the HotelReservationService to reserve a hotel.

How to do it...

  1. Setup AirLineReservationService, RentACarService, and HotelReservationService. We need to have these business services up and running, so WSO2 ESB can route messages to them.
  2. Download AirLineReservationService.aar, RentACarService.aar, and HotelReservationService.aar from SAMPLE-6 and copy those to wso2esb-4.8.0/samples/axis2Server/repository/services/. If there is no services directory create one.
  3. Start simple Axis2Server from wso2esb-4.8.0/samples/axis2Server.
  4. Validate whether the three business services are up and running by accessing their WSDLs.
  5. Start WSO2 ESB and login with username as admin and password also as admin. ESB will start on https://localhost:9443.
  6. Get synapse.xml from SAMPLE-6, copy the content of it, go to Main | Manage | Service Bus | Source View, and paste it there, overriding the existing and click on Update.
  7. The above will create a proxy service called TravelManagementService in the ESB, which will route messages to the three business services running in simple Axis2Server.
  8. Go to Main | Manage | Services | List. You should be able to see TravelManagementService listed there.
  9. Now let's test our set up with cURL.

    $ curl -d @request.xml -H "Content-Type: application/soap+xml action
    =arrangeMyTravel" http://localhost:8280/services/TravelManagementService

    You can get request.xml from SAMPLE-6.

How it works...

Let's have a deep look at the synapse configuration. The following explains key configuration elements:

  • When the request hits inSequence we have to first call the AirLineReservationService and need to process its response. If the response is true, only we will proceed to call RentACarService. The same applies when we call HotelReservationService.

    <send receive="rentACarSeq"> <endpoint> <address uri="…/AirLineReservationService"/> </endpoint> </send>

  • The receive attribute in the <send/> mediator will make sure the response from calling endpoint goes to the <sequence/> defined with that particular name. In this case, the response here will hit the rentACarSeq sequence. If we do not define this attribute then the response will directly go to the outSequence.
  • The rentACarSeq sequence has to process the response from the AirLineReservationService. If it's false, then it will call the processResponse sequence to send a message back to the client, without further processing. If the response is true, then rentACarSeq will proceed to call RentACarService.

    <sequence name="rentACarSeq"> <log level="full"/> <switch xmlns:xsd="..." xmlns:ns="..." source="//ns:reserveAirLineResponse/ns:return"> <case regex="false"> <sequence key="processResponse"/> </case> <default> <send receive="reserveHotelSeq"> <endpoint> <address uri="…/RentACarService"/> </endpoint> </send> </default> </switch> </sequence>

  • The processResponse sequence sends the response back to the client. Here we are using the <payloadFactory/> mediator to craft the response. Also when you want to send a response back to the client using the <send/> mediator we need to set the RESPONSE property to true prior to that.

    <sequence name="processResponse"> <payloadFactory> <format> <res:arrangeMyTravel xmlns:res="..."> <res:return>$1</res:return> </res:arrangeMyTravel> </format> <args> <arg evaluator="xml" expression="$ctx:businessServiceResponse"/> </args> </payloadFactory> <property name="RESPONSE" value="true" scope="default" type="STRING"/> <send/> </sequence>

  • A better approach to send back the response to the client was introduced from WSO2 ESB 4.8.0 onwards. There you need to use the <respond> mediator instead of the above.

Summary

So now you have a brief idea about WSO2 ESB. We also learnt how to cater a request from the client using Service Chaining. We've also learnt that the ESB removes point-to-point dependencies in your system to build a highly scalable and loosely coupled solution. And lastly, we have learnt the difference between Scatter and Gather EIP and Service Chaining.

Resources for Article:


Further resources on this subject:


Enterprise Integration with WSO2 ESB Over 15 recipes to calibrate seamless modularity to SOA and address commonly-faced enterprise integration challenges with a zero-code approach with this book and ebook
Published: October 2013
eBook Price: $20.99
Book Price: $34.99
See more
Select your format and quantity:

About the Author :


Prabath Siriwardena

Prabath Siriwardena is the Director of Security Architecture at WSO2 Inc., a company that produces a wide variety of open source software from data to screen. Before that he chaired the Management Committee—Integration Technologies at WSO2. He completed his degree and then a Masters from the University of Moratuwa, Sri Lanka. He is a member of OASIS Identity Metasystem Interoperability (IMI) TC, OASIS eXtensible Access Control Markup Language (XACML) TC, and OASIS Security Services (SAML) TC. He is also a member of Apache Axis PMC. He has spoken at numerous international conferences including OSCON, ApacheCon, WSO2Con, EIC, and IDentity Next. He has more than 9 years industry experience and has worked with many Fortune 100 companies.

Books From Packt


JBoss ESB Beginner’s Guide
JBoss ESB Beginner’s Guide

Microsoft BizTalk ESB Toolkit 2.1
Microsoft BizTalk ESB Toolkit 2.1

Mule ESB Cookbook
Mule ESB Cookbook

 Oracle SOA Infrastructure Implementation Certification Handbook (1Z0-451)
Oracle SOA Infrastructure Implementation Certification Handbook (1Z0-451)

 Oracle E-Business Suite R12 Supply Chain Management
Oracle E-Business Suite R12 Supply Chain Management

 Oracle SOA Suite 11g R1 Developer's Guide
Oracle SOA Suite 11g R1 Developer's Guide

 Getting Started With Oracle SOA Suite 11g R1 – A Hands-On Tutorial
Getting Started With Oracle SOA Suite 11g R1 – A Hands-On Tutorial

Oracle SOA Suite 11g Performance Tuning Cookbook
Oracle SOA Suite 11g Performance Tuning Cookbook


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software