Giter VIP home page Giter VIP logo

grpc-sample's Introduction

Sample project for a gRPC (& ReST) web service

A simple project to showcase a gRPC webservice in combination with Spring Boot. For detailed information what gRPC is, see the block quote.

Project contains three submodules, server and the corresponding client to consume the webservice. Definied .proto files have their own module, since either server and client then have the same reference compiling .proto files.

please have a look at gRPC for further information

Modules

Following listing of submodules are beeing used in this project.

Proto

Mainly used to specifiy .proto files, which are beeing used by either servers or clients. Instead of modifying every single .proto file now you can simply modifiy this one in the submodule, and the change is beeing made in all referenced maven projects.

Generating .proto files is os (operating system) independant.

Server

Server side implementation was done with grpc-spring-boot-starter. Alternatively there exists another grpc-spring-boot-starter, but the first one mentioned has more to offer out of the box.

Hint: There is no official grpc-spring-boot-starter supported by the spring-boot team.

Client

As already mentioned in section server, client side implementation was done similarily.

gRPC misc

  • On my way to exploring, understanding and implement a gRPC service I encountered a very nice tool, similar to postman.

    BloomRPC

  • A very nice introduction to gRPC with spring in Java and hands-on tutorial, I'll recommend grpc-java-example

  • For a first insight how to throw and handle errors with gRPC, this resource is helpful


kubernetes (& gRPC)

For a detailed setup with gRPC and kubernetes, have a look at gRPC kubernetes setup. If you have a running kubernetes cluster, with some finetuning the current deployment (under root directory) works for the server- & clientside.

  • server

    • exposed with loadbalancer (directly callable)
  • client

    • exposed with loadbalancer
    • calls server via dynamic grpclb (see link above)

grpc-sample's People

Contributors

anjeyy avatar

Stargazers

 avatar

Watchers

 avatar

grpc-sample's Issues

gRPC unit/integration testing

Implement JUnit Tests for gRPC calls


TODO

  • simple unit test 👈 in progress
  • grpc integration test
    • with spring context
  • extend readme

question GrpcAdvice

hi anjeyy,

I'd like some help @anjeyy, how to set up the GrpcAdvice in my project.
I've realized that you're one of the contributors from the grpc-spring-boot-starter.

I've set up a class with GrpcAdvice to get the exception from the class anotated with @GrpcService.
The problem is, I couldn't get any exception treatment once they never invoke the class anotated with GrpcAdvice

bellow part with the code, and if you can help, I'll appreciate.

@GrpcAdvice
public class GrpcExceptionAdvice {

@GrpcExceptionHandler
public Status handleInvalidArgument(IllegalArgumentException e) {
    return Status.UNAUTHENTICATED.withDescription("Não autenticado").withCause(e);
}

//Service
@GrpcService
public class SearchPersonServiceGrpcImpl extends ReactorPersonServiceGrpc.PersonServiceImplBase implements SearchPersonServiceGrpc {

@Autowired
private JwtUtil jwtUtil;

@Autowired
private PersonDatabaseExternal<PersonOrm, String> repository;

@Autowired
private OrmToResponseAdapter<EnrichmentResponseGrpc, PersonOrm> converter;

private final Log log = LogFactory.getLog(SearchPersonServiceGrpcImpl.class);

@Override
public Mono<EnrichmentResponseGrpc> enrich(Mono<EnrichmentRequestGrpc> request) {
    return request.flatMap(requestGrpc -> {
        if (isValidToken(requestGrpc.getToken())) {
            return Mono.error(new IllegalArgumentException ("error")); //throw an exception but the GrpcAdvice not invoked
        }

}
}

gRPC error handling

Similar to the ReST Errorhandling with Spring via @ControllerAdvice - gRPC proper error handling (best/good practice)

gRPC logging with sleuth

still unsure how to use sleuth within gRPC services

Logging requests throughout multiple gRPC services to trace down errors, just in case ti reverse engineer.

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.