Receiving Email Alerts¶
This application demonstrates how to send a single event via Single Simulation, and to generate alerts using filters when the threshold value is exceeded. Furthermore, it shows how to configure WSO2 Streaming Integrator Tooling to publish an alerts via e-mail. An alert is generated as an email when a high value transaction (i.e., where the value is over 5000) takes place.
Before you begin:
- Enable access to less secure apps in the gmail account you are using for this example via the Less SecureApps link.
- In the sample application, change the values for the following parameters in the
@sinkannotation as follows.
business.rules.manager(This is the sender's username.)
business-rules(This is the sender's password.)
[email protected](This is the sender's address.)
[email protected](This is the receiver's address.)
Alert for large value transaction: cardNo:(This is the subject of the email.)
Once you update the values for the above parameters, save the sample Siddhib application.
Executing the Sample¶
To execute the sample open the saved Siddhi application in Streaming Integrator Tooling, and start it by clicking the Start button (shown below) or by clicking Run => Run.
If the Siddhi application starts successfully, the following message appears in the console.
AlertsAndThresholds.siddhi - Started Successfully!.
Testing the Sample¶
To test the sample Siddhi application, simulate a single event for it via the Streaming Integrator Tooling as follows:
To open the Event Simulator, click the Event Simulator icon.
This opens the event simulation panel.
To simulate events for the
TransactionStreamstream of the
AlertsAndThresholdsSiddhi application, enter information in the Single Simulation tab of the event simulation panel as follows.
Field Value Siddhi App Name
As a result, the attributes of the
Transactiontreamstream appear as marked in the image above.
Enter values for the attributes as follows:
Attribute Value creditCardNo
To generate an email alert, you need to simulate an event where the transaction value (i.e.,
5000. This is indicated by the
[quantity * price > 5000]filter connected to the
Viewing the Results¶
To view the results, check the receiver Gmail inbox (i.e., Gmail specified via the
to parameter in the sink configuration). The following is displayed.
Subject: Alert for large value transaction: cardNo:1234567898765432 Content: creditCardNo:"1234567898765432", country:"SL", item:"mobile", quantity:100, price:5000
Click here to view the sample Siddhi application.
@App:name("AlertsAndThresholds") @App:description('Simulate a single event and receive alerts as e-mail when a predefined threshold value is exceeded') define stream TransactionStream(creditCardNo string, country string, item string, quantity int, price double); @sink(type='email', username ='business.rules.manager', address ='[email protected]', password= 'business-rules', subject='Alert for large value transaction: cardNo:', to='[email protected], receiv[email protected]', port = '465', host = 'smtp.gmail.com', ssl.enable = 'true', auth = 'true', @map(type='text')) define stream AlertStream(creditCardNo string, country string, item string, quantity int, price double); --Filter events when quantity * price > 5000 condition is satisfied @info(name='query1') from TransactionStream[quantity * price > 5000] select * insert into AlertStream;