Publishing JSON Events via TCP
Purpose¶
This application demonstrates how to configure WSO2 Integrator: SI Tooling to send sweet production events via TCP transport in JSON format, and view the output in the console.
Executing the sample¶
- Open a terminal and navigate to the
<SI-Tooling-Home>/samples/sample-clients/tcp-serverdirectory and run the following command:
ant -Dtype=json -Dcontext=LowProductionAlertStream
- Start the Siddhi application by clicking on 'Run'.
- If the Siddhi application starts successfully, the following messages appear on the console.
PublishTcpInJsonFormat.siddhi - Started Successfully!- 'tcp' sink at 'LowProducitonAlertStream' stream successfully connected to 'localhost:9892'.`
- Open the 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: PublishTcpInJsonFormat -
Stream Name:SweetProductionStream -
In the 'name' field and 'amount' field, enter 'toffee' and '45.24' respectively and click Send to send the event.
- Send some more events.
- See the output in the terminal of
<SI-Tooling-Home>/samples/sample-clients/tcp-server. You can see output similar to the following:
[java] [org.wso2.si.tcp.server.TCPServer] : Event{timestamp=1512446413468, data=[toffee, 45.25], isExpired=false}
[java] [org.wso2.si.tcp.server.TCPServer] : Event{timestamp=1512446425113, data=[coffee, 9.78], isExpired=false}
[java] [org.wso2.si.tcp.server.TCPServer] : Event{timestamp=1512446442300, data=[chocolate, 78.23], isExpired=false}
Notes¶
If you need to edit this application while it is running, stop the application -> Save -> Start.
If you see the message 'LowProducitonAlertStream' stream could not connect to 'localhost:9892', it could be due to the port 9892, defined in the Siddhi application. This port is already being used by a different program. To resolve this issue, please do the following:
- Stop this Siddhi application (click 'Run' on menu bar -> 'Stop').
- Change the port 9892 to an unused port in this Siddhi application's source configuration and also change the port number in the tcp-server file.
- Start the application and check whether the expected output appears on the console.
@App:name("PublishTcpInJsonFormat")
@App:description('Send events via TCP transport using json format')
define stream SweetProductionStream (name string, amount double);
@sink(type='tcp', url='tcp://localhost:9892/LowProductionAlertStream',
@map(type='json'))
define stream LowProductionAlertStream (name string, amount double);
from SweetProductionStream
select *
insert into LowProductionAlertStream;