0

I am using stream processor 4.3.0 I have created one siddhi app which has source as mqtt and message type as json

and in sink as well I am using mqtt and message as json. Basically, there is no transformation of message required.

in source mqtt topic messages are in following way

{
"value1" : 59.698437,
"value2" : 14.977777,
"valid" : true
}

which ideally should be sent to the sink mqtt broker topic.

Now, to test this, I am using event simulator in /editor to test the sidhi app. After entering the dummy values, this generates feed as

{
"event" : {
    "value1" : "59.698437",
    "value2" : "14.977777",
    "valid" : true
}

which is successfully transferred to the sink topic.

Now, in the actual message feed and generated by simulator has difference. It has event object in message which is why the editor understand that and make other messages (which does not has event object) as invalid. Is there any way, that stream processor can process the feeds without events as well and how can this be checked that sinked messages are not having event?

1 Answer 1

0

You have to use custom mapping in JSON mapper type to parse the desired JSON input

@source(type='mqtt', 
@map(type='json', enclosing.element="$", @attributes(value1 = "value1", value2 = "value2", isValid = "valid")))
define stream InputStream(value1 string, value2 string, isValid bool);

See examples under API docs for more info, https://siddhi-io.github.io/siddhi-map-json/api/4.1.1/#json-source-mapper

You can use log sink type to check the published event. Make sure to use the same map configs,

@sink(type='log', 
@map(type='json', enclosing.element="$", @attributes(value1 = "value1", value2 = "value2", isValid = "valid")))

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Niveathika for your answer here. But, as per documentation (siddhi-io.github.io/siddhi-map-json/api/4.1.1/…) this is an optional confiuguration. Can we disable that so that if the source feed does not have, then sink feed also should not get this? I got that enclosing.element=<"element"> is to add in case we need it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.