我們將 Golang 和 .NET Core 用于我們的相互通信微服務(wù)基礎(chǔ)架構(gòu)。服務(wù)中的所有數(shù)據(jù)都基于我們創(chuàng)建的 Protobuffs 協(xié)議。這是我們的 Protobuffs 之一的示例:syntax = "proto3";package Protos;option csharp_namespace = "Protos";option go_package="Protos";message EventMessage { string actionType = 1; string payload = 2; bool auditIsActive = 3;}Golang 運(yùn)行良好,服務(wù)根據(jù)需要生成內(nèi)容并將其發(fā)送到 SQS 隊(duì)列,一旦發(fā)生這種情況,.NET 核心服務(wù)將獲取數(shù)據(jù)并嘗試對(duì)其進(jìn)行序列化。以下是 SQS 消息示例的內(nèi)容:{"@type":"type.googleapis.com/Protos.EventMessage","actionType":"PushPayload","payload":"<<INTERNAL>>"}但是我們得到一個(gè)例外,說電線類型未定義如下所述:Google.Protobuf.InvalidProtocolBufferException: Protocol message contained a tag with an invalid wire type. at Google.Protobuf.UnknownFieldSet.MergeFieldFrom(CodedInputStream input) at Google.Protobuf.UnknownFieldSet.MergeFieldFrom(CodedInputStream input) at Google.Protobuf.UnknownFieldSet.MergeFieldFrom(UnknownFieldSet unknownFields, CodedInputStream input) at Protos.EventMessage.MergeFrom(CodedInputStream input) in /Users/maordavidzon/projects/github_connector/GithubConnector/GithubConnector/obj/Debug/netcoreapp3.0/EventMessage.cs:line 232 at Google.Protobuf.MessageExtensions.MergeFrom(IMessage message, Byte[] data, Boolean discardUnknownFields, ExtensionRegistry registry) at Google.Protobuf.MessageParser`1.ParseFrom(Byte[] data)兩個(gè)服務(wù)中的 Proto 文件完全相同。我們需要添加任何潛在的缺失選項(xiàng)或?qū)傩詥幔?
2 回答

小怪獸愛吃肉
TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超1個(gè)贊
看起來您使用的是 JSON 格式而不是二進(jìn)制格式。在這種情況下,您想要ParseJson(string json)
,而不是ParseFrom(byte[] data)
。
注意:二進(jìn)制格式更有效,如果這對(duì)您很重要。它還對(duì) protobuf 庫/工具有更好的支持。

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
基本上有兩種可能的情況,或者您為 .NET 和 GoLang 生成的 protos 文件不在同一版本中,或者您的數(shù)據(jù)在 GoLang 和 .NET 應(yīng)用程序之間傳輸時(shí)已損壞。
Protobuf 是一個(gè)二進(jìn)制協(xié)議,請(qǐng)檢查您是否有任何 http 過濾器或其他任何可以更改傳入或傳出字節(jié)流的東西。
- 2 回答
- 0 關(guān)注
- 257 瀏覽
添加回答
舉報(bào)
0/150
提交
取消