GithubHelp home page GithubHelp logo

codestruggle / grpc-spring-boot-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grpc-ecosystem/grpc-spring

0.0 2.0 0.0 180 KB

Spring Boot starter module for gRPC framework.

License: MIT License

Java 100.00%

grpc-spring-boot-starter's Introduction

Grpc Spring Boot Starter

Build Status

README: English | δΈ­ζ–‡

Features

Auto configuring and run the embedded gRPC server with @GrpcService-enabled beans as part of spring-boot application.

Support Spring Cloud(registe services to consul or eureka and fetch gRPC server information)

Support Spring Sleuth to trace application

Support global and customer gRPC server/client interceptors

Support keepalive

Usage

gRPC server

To add a dependency using Maven, use the following:

<dependency>
  <groupId>net.devh</groupId>
  <artifactId>grpc-server-spring-boot-starter</artifactId>
  <version>1.0.0.RELEASE</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  compile 'net.devh:grpc-server-spring-boot-starter:1.0.0.RELEASE'
}

Annotate your server interface implementation(s) with @GrpcService

@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();
    }
}

gRPC client

To add a dependency using Maven, use the following:

<dependency>
  <groupId>net.devh</groupId>
  <artifactId>grpc-client-spring-boot-starter</artifactId>
  <version>1.0.0.RELEASE</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  compile 'net.devh:grpc-client-spring-boot-starter:1.0.0.RELEASE'
}

Use @GrpcClient("gRPC server name") annotation or grpcChannelFactory.createChannel("gRPC server name") to get Channel

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

set gRPC host and port in application.properties, default host is 0.0.0.0 and default port is 9090

grpc.server.port=
grpc.server.host=

gRPC request

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

set gRPC server host and port in application.properties, default host is [127.0.0.1] and default port is [9090]

grpc.client.(gRPC server name).host[0]=
grpc.client.(gRPC server name).port[0]=

Version Compatibility with gRPC

Note: The version numbers below are only examples

Project Version gRPC Version
1.0.1.SNAPSHOT 1.1.2
1.0.0.RELEASE 1.0.3

Show case

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

Credits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.