Skip to content

API Docs - v1.0.0

Tested Siddhi Core version: 5.1.5

It could also support other Siddhi Core minor versions.

Sinkmapper

protobuf (Sink Mapper)

This output mapper allows you to convert Events to protobuf messages before publishing them. To work with this mapper you have to add auto-generated protobuf classes to the project classpath. When you use this output mapper, you can either define stream attributes as the same names as the protobuf message attributes or you can use custom mapping to map stream definition attributes with the protobuf attributes..Please find the sample proto definition here

Syntax

@sink(..., @map(type="protobuf", class="<STRING>")

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
class

This specifies the class name of the protobuf message class, If sink type is grpc then it's not necessary to provide this parameter.

- STRING Yes No

Examples EXAMPLE 1

@sink(type='grpc',  url = 'grpc://localhost:2000/org.wso2.grpc.test.MyService/process 
@map(type='protobuf')) 
define stream BarStream (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double)

Above definition will map BarStream values into the protobuf message type of the 'process' method in 'MyService' service

EXAMPLE 2

@sink(type='grpc', url = 'grpc://localhost:2000/org.wso2.grpc.test.MyService/process
@map(type='protobuf'), 
@payload(stringValue='a',longValue='b',intValue='c',booleanValue='d',floatValue = 'e', doubleValue  = 'f'))) 
define stream BarStream (a string, b long, c int,d bool,e float,f double);

The above definition will map BarStream values to request message type of the 'process' method in 'MyService' service. and stream values will map like this,
- value of 'a' will be assign 'stringValue' variable in the message class
- value of 'b' will be assign 'longValue' variable in the message class
- value of 'c' will be assign 'intValue' variable in the message class
- value of 'd' will be assign 'booleanValue' variable in the message class
- value of 'e' will be assign 'floatValue' variable in the message class
- value of 'f' will be assign 'doubleValue' variable in the message class

EXAMPLE 3

@sink(type='grpc', url = 'grpc://localhost:2000/org.wso2.grpc.test.MyService/testMap' 
@map(type='protobuf')) 
 define stream BarStream (stringValue string,intValue int,map object);

The above definition will map BarStream values to request message type of the 'testMap' method in 'MyService' service and since there is an object data type is inthe stream(map object) , mapper will assume that 'map' is an instance of 'java.util.Map' class, otherwise it will throws and error.

EXAMPLE 4

@sink(type='inMemory', topic='test01', 
@map(type='protobuf', class='org.wso2.grpc.test.Request'))
define stream BarStream (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double);

The above definition will map BarStream values to 'org.wso2.grpc.test.Request'protobuf class type. If sink type is not a grpc, sink is expecting to get the mapping protobuf class from the 'class' parameter in the @map extension

Sourcemapper

protobuf (Source Mapper)

This input mapper allows you to convert protobuf messages into Events. To work with this input mapper you have to add auto-generated protobuf classes to the project classpath. When you use this input mapper, you can either define stream attributes as the same names as the protobuf message attributes or you can use custom mapping to map stream definition attributes with the protobuf attributes..Please find the sample proto definition here

Syntax

@source(..., @map(type="protobuf", class="<STRING>")

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
class

This specifies the class name of the protobuf message class, If sink type is grpc then it's not necessary to provide this field.

- STRING Yes No

Examples EXAMPLE 1

source(type='grpc', receiver.url = 'grpc://localhost: 2000/org.wso2.grpc.test.MyService/process', 
@map(type='protobuf')) define stream FooStream (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double); 

Above definition will convert the protobuf messages that are received to this source into siddhi events.

EXAMPLE 2

source(type='grpc', receiver.url = 'grpc://localhost: 2000/org.wso2.grpc.test.MyService/process', 
@map(type='protobuf', @attributes(a = 'stringValue', b = 'intValue', c = 'longValue',d = 'booleanValue',' e = floatValue', f ='doubleValue'))) 
define stream FooStream (a string ,c long,b int, d bool,e float,f double);

Above definition will convert the protobuf messages that are received to this source into siddhi events. since there's a mapping available for the stream, protobuf message object will be map like this,
-'stringValue' of the protobuf message will be assign to the 'a' attribute of the stream
- 'intValue' of the protobuf message will be assign to the 'b' attribute of the stream
- 'longValue' of the protobuf message will be assign to the 'c' attribute of the stream
- 'booleanValue' of the protobuf message will be assign to the 'd' attribute of the stream
- 'floatValue' of the protobuf message will be assign to the 'e' attribute of the stream
- 'doubleValue' of the protobuf message will be assign to the 'f' attribute of the stream

EXAMPLE 3

source(type='grpc', receiver.url = 'grpc://localhost: 2000/org.wso2.grpc.test.MyService/testMap', 
@map(type='protobuf')) 
define stream FooStream (stringValue string ,intValue int,map object);

Above definition will convert the protobuf messages that are received to this source into siddhi events. since there's an object type attribute available in the stream (map object), mapper will assume that object is an instance of 'java.util.Map' class. otherwise mapper will throws an exception

EXAMPLE 4

@source(type='inMemory', topic='test01', 
@map(type='protobuf', class='org.wso2.grpc.test.Request')) 
define stream FooStream (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double); 

The above definition will convert the 'org.wso2.grpc.test.Request' type protobuf messages into siddhi events. If we did not provide the 'receiver.url' in the stream definition we have to provide the protobuf class name in the 'class' parameter inside @map.