跳到主要内容
版本:Next
protobufCODEC

Protobuf

Protobuf 编解码器(Codec)使用启动时从 .proto 文件编译出的描述符,在二进制 Protobuf 消息与列式 Arrow RecordBatch 之间相互转换。解码按配置的 MessageDescriptor 解析每个字节负载;编码则执行相反的过程。当输入产生原始 Protobuf(不带 Confluent schema-id 前缀)时使用它。

配置​

FieldTypeRequiredDefault描述
typestringyes—固定值 "protobuf"
message_typestringyes—完全限定的 Protobuf 消息类型名(包含包名),如 com.example.User
proto_inputsarray<string>yes—.proto 源文件路径列表
proto_includesarray<string>no—解析 .proto 文件时使用的 include 搜索路径

解码错误策略是 codec 上的引擎级 on_error 键——见死信队列。

示例​

input:
type: kafka
brokers:
- localhost:9092
topics:
- users
consumer_group: arkflow
start_from_latest: false
codec:
type: protobuf
message_type: message.Message
proto_inputs:
- ./examples/message.proto
codec:
type: protobuf
message_type: message.Message
proto_inputs:
- ./examples/message.proto

说明​

  • 仅支持 proto3 标量字段:bool、int32/sint32/sfixed32、int64/sint64/sfixed64、uint32/fixed32、uint64/fixed64、float、double、string、bytes 以及 enum(映射为 Arrow Int32)。
  • 不支持嵌套消息、repeated、map、oneof 以及 proto3 的 optional 字段;在编码/解码时遇到它们会返回错误。
  • 解码使用 descriptor 的完整字段集对单个累积批次进行:每个解码出的字段都是 nullable,消息缺省某字段时该列直接取 null(不存在按消息的 schema 合并,也没有跨消息兼容性检查)。