Publishing XML Events via HTTP¶
Purpose¶
This application demonstrates how to configure WSO2 Integrator: SI Tooling to send sweet production events via HTTP transport in XML default format and log the events in LowProductionAlertStream to the output console.
Before executing the sample:
Save the sample Siddhi application. Is there is no syntax error, the following message appears in the console.
Siddhi App PublishHttpInXmlFormat successfully deployed.
Executing the sample¶
- Start the Siddhi application by clicking Run => Run.
- If the Siddhi application starts successfully, the following messages are shown on the console.
PublishHttpInXmlFormat.siddhi - Started Successfully!'Http' sink at 'LowProductionAlertStream' stream successfully connected to 'localhost:8080/abc'.
Testing the sample¶
- Open a terminal and navigate to
<SI-Tooling-Home>/samples/sample-clients/http-server. Then run theantcommand without any arguments. -
Send events using one or more of the following methods:
-
Send events with http server through the event simulator:
a. Open the event simulator by clicking on the second icon or pressing Ctrl+Shift+I.
b. In the Single Simulation tab of the panel, specify the values as follows: -
Siddhi App Name: PublishHttpInXmlFormat -Stream Name:SweetProductionStreamc. In the name and amount fields, enter
toffeesand75.6respectively and then click Send to send the event.d. Send more events as required.
-
Send events to the HTTP endpoint defined by
publish.urlin the Sink configuration using the curl command:a. Open a new terminal and issue the following command.
```bash curl -X POST -d '{"streamName": "SweetProductionStream", "siddhiAppName": "PublishHttpInXmlFormat","data": ['toffees', 75.6]}' http://localhost:9390/simulation/single -H 'content-type: text/plain' ```b. If there is no error, the following message appears in the terminal.
```bash {"status":"OK","message":"Single Event simulation started successfully"} ``` -
Publish events with Postman:
a. Launch the Postman application.
b. Make a 'Post' request to the
http://localhost:9390/simulation/singleendpoint. Set the Content-Type totext/plainand set the request body in text as follows.`{"streamName": "SweetProductionStream", "siddhiAppName": "PublishHttpInXmlFormat","data": ['toffees', 75.6]}`c. Click Send. If there is no error, the following messages appear in the console.
-"status": "OK",
-"message": "Single Event simulation started successfully"
-
Viewing the results¶
See the output on the terminal.
Note
If the message LowProductionAlertStream stream could not connect to localhost:8080, it could be because the port 8080
defined in the Siddhi application is already being used by a different program. To resolve this issue, do the following:
1. Stop this Siddhi application (Click 'Run' on menu bar -> 'Stop').
2. Change the port from 8080 to an unused port in this Siddhi application's source configuration and in the http-server file.
3. Start the application and check whether the expected output appears in the console.
@App:name("PublishHttpInXmlFormat")
@App:description('Send events via HTTP transport using XML format')
define stream SweetProductionStream (name string, amount double);
@sink(type='http', publisher.url='http://localhost:8080/abc',
@map(type='xml'))
define stream LowProductionAlertStream (name string, amount double);
@info(name='query1')
from SweetProductionStream
select *
insert into LowProductionAlertStream;