API Docs - v1.1.1
Tested Siddhi Core version: 5.1.21
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. When you use this mapper with siddhi-io-grpc
you don't have to provide the protobuf message class in the class
parameter.
@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='inMemory', topic='test01',
@map(type='protobuf', class='io.siddhi.extension.map.protobuf.autogenerated.Request'))
define stream BarStream (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double);
This will map BarStream
values into io.siddhi.extension.map.protobuf.autogenerated.Request
protobuf message type.
EXAMPLE 2
@sink(type='grpc', publisher.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 messages. Since this is a grpc
sink, protobuf mapper will get the type of the protobuf class by the publisher.url
.
EXAMPLE 3
@sink(type='grpc', publisher.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);
This 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 4
@sink(type='inMemory', topic='test01',
@map(type='protobuf' class='io.siddhi.extension.map.protobuf.autogenerated.RequestWithList'))
define stream BarStream (stringValue string,intValue int,stringList object, intList object);
This will map BarStream
values into io.siddhi.extension.map.protobuf.autogenerated.RequestWithList
. If you want to map data types other than the scalar data types, you have to use object
as the data type as shown in above(stringList object
).
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. When you use this mapper with siddhi-io-grpc
you don't have to provide the protobuf message class in the class
parameter.
@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='inMemory', topic='test01',
@map(type='protobuf', class='io.siddhi.extension.map.protobuf.autogenerated.Request'))
define stream FooStream (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double);
This will convert the io.siddhi.extension.map.protobuf.autogenerated.Request
protobuf messages into siddhi events.
EXAMPLE 2
source(type='grpc', receiver.url = 'grpc://localhost:8084/org.wso2.grpc.test.MyService/process',
@map(type='protobuf')) define stream FooStream (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double);
This will convert the protobuf messages that are received to this source into siddhi events. Since this is grpc
source we don't need to provide the class
parameter
EXAMPLE 3
source(type='grpc', receiver.url = 'grpc://localhost:8084/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);
This 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 4
source((type='inMemory', topic='test01',
@map(type='protobuf', class='io.siddhi.extension.map.protobuf.autogenerated.RequestWithList))
define stream FooStream (stringValue string ,intValue int,stringList object, intList object););
This will convert the io.siddhi.extension.map.protobuf.autogenerated.RequestWithList
protobuf messages that are received to this source into siddhi events. If you want to map data types other than the scalar data types, you have to use object
as the data type as shown in above(stringList object
)