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

Invalid Protocol Buffer schema. Import "google/protobuf/any.proto" has not been loaded: GCP/Pub-Sub

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

架构:

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;
}

此模式的验证失败并出现错误

Invalid Protocol Buffer schema. Import "google/protobuf/any.proto" has not been loaded.

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

目前,Pub/Sub 的模式支持不支持导入。您必须在消息类型的定义中自己定义消息类型。另请注意,当前模式支持仅允许定义单个消息顶部消息类型,因此您还必须将 Endorsement 定义嵌入 TransactionPayload 定义中。