Month: November 2012

Basic Alert System With WSO2 ESB


Recently I got a chance to come across different service enterprise integration patterns. Under that Test Message pattern I have read, made my mind to do this type of work. In here I’m using WSO2 ESB, which has become familiar to me. So I suppose that you are also familiar with that.

What I’m going to do

In here I’m going to check the availability of a backend service periodically/at a given time, and if the service is not available at that time corresponding user will get an email. In the following example I’m explaining about a basic scenario, but this can be expanded to scenarios with various transports, various messaging formats, etc.

For this example I’m using latest WSO2 ESB version 4.5.1. Backend service can be your own or a service provided with samples. For more information look here.

The design of the ESB configuration can be shown as follows. You can see that injecting a test message will not affect the normal flow of the messages. For injecting Test message main sequence must be used.

Scheduled Tasks

Scheduled Tasks in WSO2 ESB is used here to produce Test massages. You can set scheduled tasks to inject messages periodically by setting interval parameter or at a particular time by setting a corn expression. I’m not going to discuss on more about Scheduled Tasks here, but you here for more information.

Axis2 Configuration

To enable sending emails, you have to enable smtp transport in axis2 configuration in WSO2 ESB. (resides in /wso2esb-4.5.1/repository/conf/axis2 folder). So it should be look like follow.

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
 <parameter name=""></parameter>
 <parameter name="mail.smtp.port">587</parameter>
 <parameter name="mail.smtp.starttls.enable">true</parameter>
 <parameter name="mail.smtp.auth">true</parameter>
 <parameter name="mail.smtp.user"></parameter>
 <parameter name="mail.smtp.password">your_sending_email_password</parameter>
 <parameter name="mail.smtp.from"></parameter>

Then you need to enable “text/html” message formatter.

<messageFormatter contentType="text/html" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>

Setting Configuration

Thereafter you have  to add the following configuration to Synapse. Explanations are done along with the configuration

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="">
 <proxy name="ServiceProxy" transports="https http" startOnLoad="true" trace="disable">
  <target inSequence="sendSeq"/>

<!-- Scheduled task to send messages -->
 <task name="Testing" group="synapse.simple.quartz">
 <!-- produce messages every 25 seconds, this can be replaced by a corn expression -->
 <trigger interval="25"/>

<!-- Create the payload for test message -->
 <property xmlns:task="" name="message">
 <m0:getQuote xmlns:m0="http://services.samples">

 <property xmlns:task="" name="soapAction" value="urn:getQuote"/>
 <property xmlns:task="" name="to" value="http://localhost:9000/services/SimpleStockQuoteService"/>

<!-- For injecting test messages in to normal message flow -->
 <sequence name="main">
 <sequence key="sendSeq"/>

<!-- sending messages to backend , if available respond will be send to "receiveSeq"-->
 <sequence name="sendSeq">
 <send receive="receiveSeq">
 <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>

<!-- If there's any fault condition messages are directed to here -->
 <sequence name="fault">

<!-- filter out the failed Test Messages -->
 <filter xmlns:ns="http://org.apache.synapse/xsd" xmlns:m0="http://services.samples" source="//m0:getQuote/m0:request/m0:symbol" regex="TEST">
 <property name="Subject" value="Alert Message From WSO2 ESB - Service Down !!!" scope="transport" type="STRING"/>
 <property name="MessageType" value="text/html" scope="axis2" type="STRING"/>
 <property name="ContentType" value="text/html" scope="axis2" type="STRING"/>
 <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>

<!-- should be changed according to your scenario -->
 <address uri=""/>


<!-- sequence which receives replies from back end service, if available-->
 <sequence name="receiveSeq">
 <filter xmlns:ax21="http://services.samples/xsd" xmlns:ns="http://org.apache.synapse/xsd" source="//ax21:symbol" regex="TEST">
 <property name="TEST PASSED" value="*** Test Message Passed ***"/>
 <property name="TESTED SERVICE" value="*** localhost:9000/services/SimpleStockQuoteService ***"/>


Now you can start WSO2 ESB alone, so since you test message can’t send to back-end service you will get an email as follows.


[1] WSO2 ESB:

[2] Sending Emails with WSO2 ESB:

[3] Setting mail  transport in WSO2 ESB:

[4] WSO2 ESB Scheduled Tasks:

[5] Test Message EIP: