首页 > 解决方案 > 这对 proto 文件来说是一个糟糕的结构吗

问题描述

在尝试制作具有多项服务的 gRPC 应用程序时遇到了巨大的困难,并且无法找到我的问题的原因。开始认为它可能在原型代码的结构中。

message Room {
    enum Location {
        Unknown = 0;
        Hallway = 1;
        MaleWC = 2;
        FemaleWC = 3;
        Office = 4;
        Kitchen = 5;
        ConferenceRoom = 6;
    }
    Location room = 1;
    int32 capacity = 2;
    int32 population = 3;
    bool light = 4;
    bool lock = 5;
}
 
service lightandtempcontrol {
 
    // create a name for the rpc first -> then specify type of message to send to server
    // to turn a light on upon somebody entering a room
    rpc LightsOn(targetLight) returns (emptyMessage) {}; // Unary*
    // to turn a light off upon someone entering the room
    rpc LightsOff(targetLight) returns (lightReceipt) {};
    //to regulate temperature dependent on the temperature outside
    rpc OutsideTemp(stream outTemp) returns (stream indoorTemp){}; // Bidirectional*
    //to get a complete 
    rpc Usage(usageRequest) returns (stream lightUsage) {}; // Server streaming example
 
}

基本上,我正在尝试创建一个可以与多个服务一起使用的 Room 类,在这些服务中获取和设置字段,但是每次我尝试基于其中一个的代码时,我都会得到不想要的结果,主要是因为我想要的值更改或比较根本不起作用。是我的原型结构中的问题。是否可以在 lightandtempcontrol 之外的其他服务中使用此 Room 消息?

标签: grpcgrpc-javaproto

解决方案


推荐阅读