Search code examples
wso2siddhi

How can i provide input data to inputHandler


I am unable to find any use case or any documentation where it's mentioned that how we can provide input data to inputHandler without hardocding it while using siddhi as a library.

All i found on internet is inputHandler with static data. ex :- inputHandler.send(new Object[]{"WSO2", 50f, 30L}); etc..,

I want to know how we can pass JSON data to inputHandler or streams while using siddhi as a library ?


Solution

  • In siddhi a simple data flow can be depicted as below.

    source(input) -> sourceMapper -> stream > {queries -> stream} -> .... stream -> sinkMapper -> sink(output)

    When using siddhi as a library, InputHandler is used to provide data to a stream.

    But when you provide data directly to a stream, mapping won't be happening. Therefore, you have to provide exact values for each attributes of the relevant stream.

    If you need to programatically provide data to the source level, you can use a source of type "inMemory" [1] and then provide the data using an InMemoryBroker [2]

    Please refer to the code [3] for an example.

    [1] https://github.com/wso2-extensions/siddhi-map-json/blob/master/component/src/test/java/org/wso2/extension/siddhi/map/json/sourcemapper/JsonSourceMapperTestCase.java#L52

    [2] https://github.com/wso2-extensions/siddhi-map-json/blob/master/component/src/test/java/org/wso2/extension/siddhi/map/json/sourcemapper/JsonSourceMapperTestCase.java#L87

    [3] https://github.com/wso2-extensions/siddhi-map-json/blob/master/component/src/test/java/org/wso2/extension/siddhi/map/json/sourcemapper/JsonSourceMapperTestCase.java