Eventing support is provided by the WS-Eventing Web services standard. When a data service request or response triggers an event, the subscribers listening to those events receive notifications. The criteria for triggering an event as well as the destination to which the event notifications should be sent are defined per data service query. When a certain event-trigger is activated, emails will be sent to all the respective subscribers.
...
Update email configurations: Open the
axis2_client.
xml file from xml file from the<EI_HOME>/conf/axis2
folder and add the following XML element:Code Block <transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender"> <parameter name="mail.smtp.from">esb.sample@gmail.com</parameter> <parameter name="mail.smtp.user">esb.sample</parameter> <parameter name="mail.smtp.password">esb*sample8</parameter> <parameter name="mail.smtp.host">smtp.gmail.com</parameter> <parameter name="mail.smtp.port">587</parameter> <parameter name="mail.smtp.starttls.enable">true</parameter> <parameter name="mail.smtp.auth">true</parameter> </transportSender>
Set up a datasource:
- Install the MySQL server.
Download the JDBC driver for MySQL from here and copy it to your to your
<EI_HOME>/wso2/lib
directory.Create the following database: Company
Create the ACCOUNT table in the Company database:
Code Block CREATE TABLE ACCOUNT(AccountID int NOT NULL,Branch varchar(255) NOT NULL, AccountNumber varchar(255),AccountType ENUM('CURRENT', 'SAVINGS') NOT NULL,Balance FLOAT,ModifiedDate DATE,PRIMARY KEY (AccountID));
Enter the following data into the ACCOUNT table:
Code Block INSERT INTO ACCOUNT VALUES (1,"AOB","A00012","CURRENT",231221,'2014-12-02');
...
- Log into the management console of the ESB of WSO2 EI and EI and click Create in the Data Service menu.
- Add a name for the data service and go to the next step.
- Connect to the Company database that you defined above.
Enter the URL to your MySQL database in the URL field: jdbc:mysql://localhost:3306/Company
Enter the username and password to connect to your MySQL database. By default the username is root and the password is blank.
- Click Next to go to the Queries screen.
- Click Add New Query to specify the query details:
Enter UpdateAccBalance as the query ID.
Enter the following SQL dialect:
Code Block UPDATE ACCOUNT SET Balance=:Balance WHERE AccountID=:AccountID
- Click Generate Input Mapping to automatically generate input mappings for the AccountID and Balance fields.
At the bottom of the page you will find the the Events section section:
Click Click Manage Events and and add a new event as shown below:
The fields in the the Add Events screen screen are explained below.
Event Id: account_balance_low_trigger
Info The ID used for identifying the event-trigger used in data services queries.
Xpath: /updateAccountBalanceQUpdateAccBalance/Balance<200
Info Represents an XPath expression that is run against the XML message presented. That is,the request/response message. When this evaluation returns returns
true
, the event is triggered.Target Topic: product_stock_low_topic
Info The topic to which the event notifications are published.
Event Sink URL: mailto:youremail@wso2.com
Info A subscription can be any endpoint that is complaint compliant with WS-Eventing. For example, you can use an SMTP transport to send a message to a mail inbox, where an email address is given as the subscription. Here, many subscriptions can be defined for the given topic.
Save the event.
- You can now add the event as an event trigger for the query as shown below. Since the event sends notifications related to data input, you need to add the event as an Input Event Trigger.
- Save the UpdateAccBalance query.
Create an operation for the UpdateAccBalance query as shown below.
Save the Operation.
Click Finish to navigate to the Deployed Services window from where you can manage data services.
...
- Go to the Deployed Services screen.
- Click Try this Service to open the data service from the TryIt tool.
- You will find the new operation, which you have created.
- Enter '1' as the account number, and add a value less than 200 as the balance and click on Send.
- You should receive an email when this happens.