协议缓冲区架构无效。导入“google/protobuf/any.proto”尚未加载:GCP/Pub-Sub

Nit*_*waj 7 schema protocol-buffers proto google-cloud-pubsub

我是 GCP 的新手。我正在尝试使用 protobuf 将 Pub/Sub 服务与架构定义结合使用。

架构:

syntax = "proto3";

import "google/protobuf/any.proto";

message Endorsement {
  string endorserId=1;
  google.protobuf.Any data = 2;
  string signature=3;
  bool isVerified=4;
}

message TransactionPayload {
  string policyId =1;
  string txnId =2;
  repeated Endorsement endorsements=3;
}
Run Code Online (Sandbox Code Playgroud)

此架构的验证失败并出现错误

协议缓冲区架构无效。导入“google/protobuf/any.proto”尚未加载。

在此输入图像描述

我需要使用 google.protobuf.Any,还有其他方法可以使用/定义它吗?

Kam*_*osn 4

目前,Pub/Sub 的架构支持不支持导入。您必须在消息类型的定义中自行定义消息类型。另请注意,当前架构支持仅允许定义单个消息顶级消息类型,因此您还必须将定义嵌入到定义EndorsementTransactionPayload

  • 事实证明,文档中尚未提及此限制。将确保将其添加到 https://cloud.google.com/pubsub/docs/schemas。 (2认同)