Skip to main content

protobuf

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. When you use this mapper with stream processor-io-grpc you don't have to provide the protobuf message class in the class parameter.

Syntax

CREATE SINK <NAME> WITH (type="protobuf", class="<STRING>")

Query Parameters

NameDescriptionDefault ValuePossible Data TypesOptionalDynamic
classThis specifies the class name of the protobuf message class, If sink type is grpc then it's not necessary to provide this parameter.-STRINGYesNo

Example 1

CREATE SINK BarStream WITH (type='stream', topic='test01', map.type='protobuf', map.class='io.streamprocessor.extension.map.protobuf.autogenerated.Request') (stringValue string, intValue int,longValue long,booleanValue bool,floatValue float,doubleValue double);

This will map BarStream values into io.streamprocessor.extension.map.protobuf.autogenerated.Request protobuf message type.

Example 2

CREATE SINK BarStream WITH (type='grpc', publisher.url='grpc://localhost:2000/org.gdn.grpc.test.MyService/process, map.type='protobuf') (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

CREATE SINK BarStream WITH (type='grpc', publisher.url = 'grpc://localhost:2000/org.gdn.grpc.test.MyService/process, map.type='protobuf', map.payload="stringValue='a',longValue='b',intValue='c',booleanValue='d',floatValue = 'e', doubleValue  = 'f'") (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

CREATE SINK BarStream WITH (type='stream', topic='test01', map.type='protobuf', map.class='io.streamprocessor.extension.map.protobuf.autogenerated.RequestWithList') (stringValue string,intValue int,stringList object, intList object);

This will map BarStream values into io.streamprocessor.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).