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:


8 thoughts on “Basic Alert System With WSO2 ESB

  1. Hi Buddhima,

    I am trying to do the above example but with a slight change. What my scenario is that when i use the try it option of the proxy and if i get the response it should send the mail then. I have used the above code but i have only changed this much:

    am i doing right? becouse this thing is not working for me.

  2. my changes are not visible here. What i am doing is in the sequence sendSeq, instead of i have removed the address uri and simply added the endpoiny with key = “wsdlEP”. This is the enpoint that i have created from wsdl of rule service.
    my mailing service will trigger only when i get the response and based on some keywords in the response i have to send mail to specific user group

    1. Hi Roy,
      I need more details to think of this problem.
      Can you send the synapse configuration you created and other configurations you made ?
      Another promising way to get the answer is posting your question in Stackoverflow with “WSO2” tag and relative links. WSO2 team will put best effort to answer those questions.

  3. Hi Buddhima,

    From the above post ,how can we send the data to multiple E-mail as dynamically using address endpoint.

    1. Hi Anil,
      In my post, I’m filtering fault messages before sending to address endpoint (with regex = “TEST”).Similarly, you can use multiple filters to filter a message and send to one/multiple address endpoints, according to message content.

      1. Thank you, Buddhima.

        How can we send these data dynamically to E-Mail users,(thses mails are taking dynamically from database tables).

        Could you please help me.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s