如何解决Kafka Protobuf反序列化异常:SerializationException
解决方案
针对你遇到的Protobuf序列化错误,主要问题出在消息格式和schema匹配上,按以下步骤修复:
修复JSON消息的非法数字格式
消息里的systemId值05381443带有前导零,JSON规范不允许数字有前导零(除非值为0),这是导致解析失败的直接原因。将其修改为5381443。验证Schema Registry的schema ID匹配
确认你指定的value.schema.id="1"对应的schema确实是你提供的SearchRequestproto3 schema。可以通过curl命令查询验证:curl http://vmcap78-stg.corp.netapp.com:8081/schemas/ids/1返回的schema内容必须和你给出的完全一致,否则会因schema不匹配导致序列化失败。
使用修正后的消息重新发送
替换为以下合法JSON内容后执行生产命令:{"eventVersion": 0.1, "producedBy": "ASUP_PUT", "asupSubject": "HA Group Notification from CH-GV1-NETAPP-01-01 (MetroCluster IP Statistics) NOTICE", "sysSerialNo": 2120063, "systemId": 5381443, "rawAsupPath": "/asupmail/asups/put/2022090061.3866.7z.headers", "completedTimestamp": 1659949215035, "sourceQueue": "PUT", "addOnAttributes": {"asupSecureType": "OTHERS", "sesgFlag": "False"}}
另外,你的Protobuf schema中嵌套消息addonattributes的字段名与JSON里的嵌套字段完全匹配,这部分无需修改。
内容的提问来源于stack exchange,提问作者fahadhub
相关产品推荐
相关产品推荐

