通过HTTP传输接收事件,并使用JSON输入数据查看控制台上的输出

问题描述 投票:0回答:1

我在siddhi编辑器上使用我自己的数据跟踪ReceiveAndcount示例,用于咨询需要输入数据以响应的外部URL(令牌,日期和设备ID)。此查询应返回带有日期,布尔值和三个浮点数据的JSON。

我的代码如下:

@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;

我无法获得任何结果,只有“TestingReceiveAndCount.siddhi - Siddhi AppTestingReceiveAndCount处于错误状态”。控制台中出错。

我检查了siddhi文档,我不确定是否正确地将输入数据传递给URL以获得响应

wso2 siddhi wso2sp
1个回答
0
投票

要在WSO2 SP中发送HTTP请求和接收响应,您必须使用http-request(接收器)和http响应(源)。请看下面的代码,

@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);

这里,当您使用流属性的值(或用于测试的simulate)调用localTestEventReq时,将发出请求,如果响应是代码200,则事件将到达localTestEventRes2xx。请参阅api docs了解上述水槽和水源。

© www.soinside.com 2019 - 2024. All rights reserved.