Protocol buffers 在grpc中接受域对象作为请求负载是一种反模式吗?

Protocol buffers 在grpc中接受域对象作为请求负载是一种反模式吗?,protocol-buffers,microservices,grpc,grpc-java,Protocol Buffers,Microservices,Grpc,Grpc Java,我有一个简单的服务,它包含如下消息定义 message BrandAttribute { option (gorm.opts) = { ormable: true }; atlas.rpc.Identifier id = 1 [(gorm.field).tag = {type: "serial" primary_key: true}]; string attribute_key = 2; string attribute_value = 3; atlas.rpc.Identi

我有一个简单的服务,它包含如下消息定义

message BrandAttribute {
 option (gorm.opts) = {
    ormable: true
 };
 atlas.rpc.Identifier id = 1 [(gorm.field).tag = {type: "serial" primary_key: true}];
 string attribute_key = 2;
 string attribute_value = 3;
 atlas.rpc.Identifier brand_id = 4 [(gorm.field).tag = {not_null: true}];
 Status status = 5;
}

message Brand {
 option (gorm.opts) = {
    ormable: true
 };
 atlas.rpc.Identifier id = 1 [(gorm.field).tag = {type: "serial" primary_key: true}];
 atlas.rpc.Identifier external_id = 2 [(gorm.field).tag = {type: "text" unique: true}];
 string name = 3;
 string description = 4;
 string keywords = 5;
 string meta_keywords = 6;
 string meta_description = 7;
 repeated BrandAttribute brand_attributes = 8 [(gorm.field).has_many.foreignkey = "brand_id", (gorm.field).has_many.association_foreignkey = "id"];
 Status status = 9;
}

我已经定义了用于在上述定义的enity之上实现CRUD操作的服务,但是这些服务接受品牌本身作为创建/更新操作的请求有效负载(参数),这种方法正确吗?如果不是,那么实现这一目标的最佳方式是什么。另外,如果我想使用JDBC实现persistence,我必须自己装饰protoc在protobuf定义文件中不允许的实体,我如何实现这一点?

使用
品牌作为请求的潜在问题是,如果您需要向请求添加额外信息,但如果不想将其添加到
品牌
,您将被卡住。更好的做法是针对每个服务方法,始终为其定义专用的请求和响应类型。对于您的情况,您需要发出
CreateRequest
UpdateRequest
消息等,其中包含
品牌

如何通过将
品牌
封装在
创建请求
更新请求
中来避免向
品牌
添加更多属性?因为您可以向
创建请求
添加新属性,而不是
品牌