This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Sample 663: Using Multiple Sequences
Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:
<PRODUCT_HOME>/
repository/samples/
directory that includes all Integration profile samples is changed to<EI_HOME>/
samples/service-bus/
.<PRODUCT_HOME>/
repository/samples/resources/
directory that includes all artifacts related to the Integration profile samples is changed to<EI_HOME>/
samples/service-bus/resources/
.
Introduction
This sample demonstrates how a complex sequence can be separated into a set of simpler sequences. In this sample, you will send a simple request to a back-end service (StockQuoteService
microservice) and receive a response. If you look at the sample's XML configuration, you will see how this mediation is performed by two separate sequence definitions instead of one main sequence.
Prerequisites
For a list of prerequisites, see Prerequisites to Start the ESB Samples.
Building the sample
Expand the link given below to see the XML configuration of this sample. This configuration file (synapse_sample_663.xml)
is available in the <EI_HOME>/samples/service-bus
directory.
To build the sample:
- Start the ESB profile of WSO2 EI with the sample 663 configuration. See Starting the ESB with a sample configuration for instructions.
The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds." - Start the
StockQuoteService
microservice using the MSF4j profile of WSO2 EI:- Download the
StockQuoteService
microservice and copy the JAR file to the<EI_HOME>
/wso2/msf4j/deployment/microservices
directory. - Open a command terminal, navigate to the
<EI_HOME>
/wso2/msf4j/bin
directory and start the MSF4j server by executing the relevant startup script:- On Linux: carbon.sh
- On Windows: carbon.bat
- Download the
Executing the sample
Send the following request to invoke the sample proxy service (named SequenceBreakdownSampleProxy
) in the sample.
curl -v http://localhost:8280/services/SequenceBreakdownSampleProxy -H'Content-Type:application/xml' -d'<symbol>IBM</symbol>'
When this request is sent, SequenceBreakdownSampleProxy
calls the StockQuoteSeq
sequence. This sequence calls CallStockQuoteSeq
and TransformAndRespondSeq
respectively. In CallStockQuoteSeq
, according to the symbol that is sent, the endpoint that is being called is switched using the Switch mediator. Once the response is received from the endpoint, it is transformed with TransformAndRespondSeq
, and sent back to the client. Also, note that an error sequence has been defined for each sequence, which will be executed in case of an error.
Analyzing the output
The output in the log for the above sample request would be as follows:
[2017-06-26 18:56:11,877] [EI-Core] INFO - LogMediator SEQUENCE = StockQuoteSeq|DESCRIPTION = Request recieved [2017-06-26 18:56:11,880] [EI-Core] INFO - LogMediator SEQUENCE = CallStockQuoteSeq|DESCRIPTION = Calling IBM endpoint [2017-06-26 18:56:11,941] [EI-Core] INFO - LogMediator SEQUENCE = CallStockQuoteSeq|DESCRIPTION = Response received from IBM endpoint [2017-06-26 18:56:11,942] [EI-Core] INFO - LogMediator SEQUENCE = TransformAndRespondSeq|DESCRIPTION = Response is ready to be transformed [2017-06-26 18:56:11,958] [EI-Core] INFO - LogMediator SEQUENCE = TransformAndRespondSeq|DESCRIPTION = Responding back to the client with the transformed response
As shown in the above log, since the “symbol” that is sent in the request is “IBM”, the request is routed to the IBM endpoint. Once the response from the IBM endpoint is received, it is transformed according to the specified template and sent to the client.
Shown below is the response that will be received by the client.
<Information> <Name>International Business Machines</Name> <Last>149.62</Last> <High>150.78</High> <Low>149.18</Low> </Information>