I am following the ReceiveAndcount example at siddhi editor, with my own data, for consulting to an external URL which needs input data to response (token, dates and device_id). This query should return a JSON with a date, a boolean and three float data.
My code is as follows:
@Source(type = 'http',
receiver.url='some_url',
@map(type='json',
@attributes('Token'='my_token_AAABBBCCC',
'StartDate'='2019-01-30 15:57:00',
'EndDate'='2019-01-30 15:58:00',
'Device'='device_id')))
define stream SomeStream (
date string,
ValueIsValid bool,
DATA1 float,
DATA2 float,
DATA3 float
)
-- Destination
@sink(type='log')
define stream MyOutputStream (EA1 float, EA2 float);
-- Show the selected data
@info(name='queryEA1_EA2')
from SomeStream
select EA1, EA2
insert into MyOutputStream;
I am not able to get any result, only an "TestingReceiveAndCount.siddhi - Siddhi AppTestingReceiveAndCount is in faulty state." error in the console.
I have checked the siddhi documentation and I am not sure if I am passing the input data to the URL correctly to get a response
To send HTTP requests and receive responses in WSO2 SP, you have to use, http-request(sink) and http-response(source). Please see the code below,
@sink(type = 'http-request', sink.id = 'HttpReqRes', publisher.url = 'url_to_invoke', method = 'GET',
@map(type = 'json'))
define stream localTestEventReq (token string, startdate string, enddate string, device string);
@source(type = 'http-response', sink.id = 'HttpReqRes', http.status.code = '200',
@map(type = 'json'))
define stream localTestEventRes2xx(data1 string, data1 string);
Here, when you invoke the localTestEventReq with the value for the stream attributes(or simulate for testing), a request will be sent out and if the response is of code 200, an event would arrive in localTestEventRes2xx. Please see the api docs for the above sink and source.