Manu
Manu

Reputation: 75

WSO2 SP - Kafka source with JSON attributes

I'm trying to read JSON data from Kafka, using following code:

@source(type = 'kafka', bootstrap.servers = 'localhost:9092', topic.list = 'TestTopic', 
group.id = 'test', threading.option = 'single.thread', @map(type = 'json'))

define stream myDataStream (json object);

But failed with following error:

[2019-03-27_11-39-32_103] ERROR {org.wso2.extension.siddhi.map.json.sourcemapper.JsonSourceMapper} - Stream "myDataStream" does not have an attribute named "ABC", but the received event {"event":{"ABC":"1"}} does. Hence dropping the message. Check whether the json string is in a correct format for default mapping.

I've tried adding the attributes

@source(type = 'kafka', bootstrap.servers = 'localhost:9092', 
topic.list = 'TestTopic', group.id = 'test', 
threading.option = 'single.thread', 
@map(type = 'json', @attributes(ABC = '$.ABC')))

Syntax error:

Error at 'json' defined at stream 'myDataStream', attribute 'json' is not mapped

Any help would be greatly appreciated.

Upvotes: 5

Views: 357

Answers (1)

Niveathika
Niveathika

Reputation: 1445

There is an error in the syntax of the stream,

define stream myDataStream (ABC string);

Here the attribute name is the key of the JSON messages, in this case, ABC

Upvotes: 1

Related Questions