Publishing Custom XML Events via HTTP¶
Purpose¶
This application demonstrates how to configure WSO2 Integrator: SI to send sweet production events via HTTP transport in XML format using custom mapping. Map the input events($.item.id) to stream events(name) and log the events in the LowProducitonAlertStream stream on 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 PublishHttpInXmlFormatWithCustomMapping successfully deployed.
Executing the sample¶
-
Start the Siddhi application by clicking Run => Run.
-
If the Siddhi application starts successfully, the following message appears in the console.
PublishHttpInXmlFormatWithCustomMapping.siddhi - Started Successfully!
Note
-
If you edit this application while it's running, save the application and then click Run => Run.
-
If the
PublishHttpInXmlFormatWithCustomMapping.siddhi - Started Successfully!message does not appear, it could be due to the port 8080 which is defined in the Siddhi application already being used by a different program. To resolve this issue, do the following:- Stop this Siddhi application (click 'Run' on the menu bar -> 'Stop')..
- Change the port 8080 to an unused port in this Siddhi application's source configuration..
- Start the application and check whether the specified messages appear on the console.
- Stop this Siddhi application (click 'Run' on the menu bar -> 'Stop')..
Testing the sample¶
Open a terminal and navigate to <SI-Tooling-Home>/samples/sample-clients/http-server. Then run the ant command without any arguments. Send events using one or more of the following methods:
Send events with the HTTP server through the event simulator¶
- Open event simulator by clicking on the second icon or press Ctrl+Shift+I.
- In the Single Simulation tab of the panel, select values as follows:
Siddhi App Name:PublishHttpInXmlFormatWithCustomMappingStream Name:SweetProductionStream
- In the name field and amount fields, enter
toffeeand50.0respectively. Then click Send to send the event. - Send more events.
Send events using the CURL command¶
Send event to the HTTP endpoint defined via the publish.url in the Sink configuration by issuing the following CURL command
curl -X POST -d '{"streamName": "SweetProductionStream", "siddhiAppName": "PublishHttpInXmlFormatWithCustomMapping","data": ['toffee', 67.43]}' http://localhost:9390/simulation/single -H 'content-type: text/plain'
If there is no error, the following message appears in the terminal:
{"status":"OK","message":"Single Event simulation started successfully"}
Viewing the results¶
- If you send events through the event simulator, the following output is logged.
[java] [org.wso2.si.http.server.HttpServerListener]: `Event Name Arrived: <events><event><name>toffee</name><amount>50.0</amount></event></events>`
[java] [org.wso2.si.http.server.HttpServerMain]: `Received Event Names:<events><event><name>toffee</name><amount>50.0</amount></event></events> ,`
[java] [org.wso2.si.http.server.HttpServerMain]: `Received Event Headers key set:[Http_method, Transfer-encoding, Content-type]`
[java] [org.wso2.si.http.server.HttpServerMain]: `Received Event Headers value set:[[POST], [chunked], [application/xml]]`
- If you send events through event CURL commands, the following output is logged:
[java] [org.wso2.si.http.server.HttpServerListener]: `Event Name Arrived: <events><event><name>toffee</name><amount>67.43</amount></event></events>`
[java] [org.wso2.si.http.server.HttpServerMain]: `Received Event Names:<events><event><name>toffee</name><amount>67.43</amount></event></events> ,`
[java] [org.wso2.si.http.server.HttpServerMain]: `Received Event Headers key set:[Http_method, Transfer-encoding, Content-type]`
[java] [org.wso2.si.http.server.HttpServerMain]: `Received Event Headers value set:[[POST], [chunked], [application/xml]]`
Note
Stop this Siddhi application once you are done with the execution.
@App:name("PublishHttpInXmlFormatWithCustomMapping")
@App:description('Send events via HTTP transport using xml formatwith custom mapping')
define stream SweetProductionStream (name string, amount double);
@sink(type='http', publisher.url='http://localhost:8080/abc',
@map(type='xml', @payload( "<StockData><Symbol>{{ name }}</Symbol><Price>{{ amount }}</Price></StockData>")))
define stream LowProductionAlertStream (name string, amount double);
from SweetProductionStream
select *
insert into LowProductionAlertStream;