grpc基础教程之protocol-buffers

grpc基础教程之protocol-buffers,第1张

protocol buffers:

Basics tutorial | Java | gRPC

一、包路径配置:

option java_package = "io.grpc.examples.routeguide";

二、grpc请求与返回:

 simple rpc

// Obtains the feature at a given position.
rpc GetFeature(Point) returns (Feature) {}

 server-side streaming

// Obtains the Features available within the given Rectangle.  Results are
// streamed rather than returned at once (e.g. in a response message with a
// repeated field), as the rectangle may cover a large area and contain a
// huge number of features.
rpc ListFeatures(Rectangle) returns (stream Feature) {}

  client-side streaming

// Accepts a stream of Points on a route being traversed, returning a
// RouteSummary when traversal is completed.
rpc RecordRoute(stream Point) returns (RouteSummary) {}

  server-side streaming & client-side streaming

// Accepts a stream of RouteNotes sent while a route is being traversed,
// while receiving other RouteNotes (e.g. from other users).
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}

三、message type define

// Points are represented as latitude-longitude pairs in the E7 representation
// (degrees multiplied by 10**7 and rounded to the nearest integer).
// Latitudes should be in the range +/- 90 degrees and longitude should be in
// the range +/- 180 degrees (inclusive).
message Point {
  int32 latitude = 1;
  int32 longitude = 2;
}

四、生成客户端和服务代码

POM.xml

  
        
            io.grpc
            grpc-netty-shaded
            1.30.2
        
        
            io.grpc
            grpc-protobuf
            1.30.2
        
        
            io.grpc
            grpc-stub
            1.30.2
        
         
            org.apache.tomcat
            annotations-api
            6.0.53
            provided
        
    
    
        
            
                kr.motd.maven
                os-maven-plugin
                1.6.2
            
        
        
            
                org.xolstice.maven.plugins
                protobuf-maven-plugin
                0.6.1
                
                    com.google.protobuf:protoc:3.12.0:exe:${os.detected.classifier}
                    grpc-java
                    io.grpc:protoc-gen-grpc-java:1.30.2:exe:${os.detected.classifier}
                
                
                    
                        
                            compile
                            compile-custom
                        
                    
                
            
        
    

编译:

服务端代码生成:

 客户端代码生成:

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/871612.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存