2015-08-11 11 views
19

Chiunque abbia qualche esempio o idea che usi gRPC insieme a Spring Boot?Utilizzo di Spring Boot insieme a gRPC e Protobuf

+3

https://spring.io/blog/2015/03/22/using-google-protocol-buffer-with-spring-mvc-based-rest-services è probabilmente una buona lettura. –

+0

Vero, l'ho già trovato. Ma mi piacerebbe sapere se qualcuno ha legato questo con le definizioni del servizio di protobuf pure? – Markus

+0

Anche cercare un esempio –

risposta

16

Se è ancora rilevante per te, ho creato il boot-boot-start GRPC here.

grpc-primavera-boot-starter auto-configura e gestisce il server gRPC embedded con @ GRpcService-abilitato fagioli.

L'esempio più semplice:

@GRpcService(grpcServiceOuterClass = GreeterGrpc.class) 
public static class GreeterService implements GreeterGrpc.Greeter { 

    @Override 
    public void sayHello(GreeterOuterClass.HelloRequest request, StreamObserver<GreeterOuterClass.HelloReply> responseObserver) { 
     // omitted 
    } 

} 

C'è anche un esempio di come integrare il dispositivo d'avviamento con Eureka nel file README del progetto.

2

A partire da https://spring.io/blog/2015/03/22/using-google-protocol-buffers-with-spring-mvc-based-rest-services, quindi
un'occhiata a SPR-13589 ProtobufHttpMessageConverter support for protobuf 3.0.0-beta4 e legati SPR-13203 HttpMessageConverter based on Protostuff library

Questo è qualche supporto per proto3 è in arrivo nella primavera 5. Come è in fase di sviluppo uno è incoraggiato a votare ed aumentare quello che è importante per il loro progetto.

+0

https://github.com/WThamira/gRpc-spring-boot-example è un esempio corretto per quel caso penso – wthamira

0

https://github.com/yidongnan/grpc-spring-boot-starter

In Server

@GrpcService(GreeterGrpc.class) 
public class GrpcServerService extends GreeterGrpc.GreeterImplBase { 

    @Override 
    public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) { 
     HelloReply reply = HelloReply.newBuilder().setMessage("Hello =============> " + req.getName()).build(); 
     responseObserver.onNext(reply); 
     responseObserver.onCompleted(); 
    } 
} 

Nel client

@GrpcClient("gRPC server name") 
private Channel serverChannel; 

GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(serverChannel); 
HelloReply response = stub.sayHello(HelloRequest.newBuilder().setName(name).build()); 
0

Qui io uso gRpc e eureka alla comunicazione. Questo progetto basato su Spring-boot

https://github.com/WThamira/grpc-spring-boot

inoltre Canuse registrarsi come console anche. completo esempio in questo repo

https://github.com/WThamira/gRpc-spring-boot-example

questo Maven dipendenza aiuto per gRpc

 <dependency> 
      <groupId>io.grpc</groupId> 
      <artifactId>grpc-stub</artifactId> 
      <version>1.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>io.grpc</groupId> 
      <artifactId>grpc-protobuf</artifactId> 
      <version>1.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>io.grpc</groupId> 
      <artifactId>grpc-netty</artifactId> 
      <version>1.0.1</version> 
     </dependency> 

e hanno bisogno di spettacolo plug-in sotto

 <plugin> 
       <groupId>org.xolstice.maven.plugins</groupId> 
       <artifactId>protobuf-maven-plugin</artifactId> 
       <version>0.5.0</version> 
       <configuration> 
        <!-- The version of protoc must match protobuf-java. If you don't depend 
         on protobuf-java directly, you will be transitively depending on the protobuf-java 
         version that grpc depends on. --> 
        <protocArtifact>com.google.protobuf:protoc:3.0.2:exe:${os.detected.classifier}</protocArtifact> 
        <pluginId>grpc-java</pluginId> 
        <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.1:exe:${os.detected.classifier}</pluginArtifact> 
       </configuration> 
       <executions> 
        <execution> 
         <goals> 
          <goal>compile</goal> 
          <goal>compile-custom</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
Problemi correlati