Giter Site home page Giter Site logo

motaharinia / springboot-grpc Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 479 KB

spring-boot microservice with gRPC and protobuf3. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking, and authentication.

Home Page: https://www.linkedin.com/in/motaharinia/

Java 100.00%
spring-boot grpc protobuffer protobuf3 microservice microservice-framework http2 http2-push services protocol-buffers

springboot-grpc's Introduction

Spring Boot with gRPC-protobuf(proto3) for Building Microservices

gRPC

Why gRPC?

gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.

  • Simple service definition:
    Define your service using Protocol Buffers, a powerful binary serialization toolset and language
  • Works across languages and platforms:
    Automatically generate idiomatic client and server stubs for your service in a variety of languages and platforms
  • Start quickly and scale:
    Install runtime and dev environments with a single line and also scale to millions of RPCs per second with the framework
  • Bi-directional streaming and integrated auth:
    Bi-directional streaming and fully integrated pluggable authentication with HTTP/2-based transport

Working with Protocol Buffers:

By default, gRPC uses Protocol Buffers, Google’s mature open source mechanism for serializing structured data (although it can be used with other data formats such as JSON)

Why HTTP/2?

gRPC uses HTTP/2 as its transfer protocol, so it inherits some great features that HTTP/2 offers, such as binary framing, which is high performance and robust, lighter to transport and safer to decode compared to other text-based protocols. And because it’s binary, it’s a great combination with protocol buffer.

HTTP/2 also compresses the headers using HPACK, which will reduce the overhead cost and improve the performance.

Multiplexing is possible in HTTP/2, which means the client and server can send multiple requests and responses in parallel over a single TCP connection. This will help reduce the latency and improve network utilisation.

Finally, HTTP/2 allows server-push, where with 1 single request from client, server can send back multiple responses. This is extremely valuable to reduce the round-trip latency between client and server in many cases, when server knows exactly what resources client will need and send them before they’re even requested.

We can check HTTP/2 in http://http2demo.io for check performance with HTTP/1.1

So gRPC:

  • is binary based. more efficient on the network , more efficient on cpu
  • supports multiple languages c++,Objective-c,PHP,python,Ruby,Node.js,Go,C#,Java
  • defines an interface , defines package and the payload. every field has a tag number.
  • uses Stubby a RPC framework by google for very high traffic on requests O(10^10)=10,000,000,000 RPC calls per second

On The Server We Have:

  1. proto files = human readable interface files to generate java stubs by maven plugin
  2. java stubs = java abstract classes that will be used by us to implement our services
  3. java service implementation = our implementation code for java stubs
  4. gRPC server = a server that let communicate client and server

On The Client We Have:

  1. java stubs = interfaces that can be called

Messages and Enum Sample:

https://medium.com/@akhaku/protobuf-definition-best-practices-87f281576f31

Defining Service Method and Message Names Standards:

https://developers.google.com/protocol-buffers/docs/style

Variable Types in Proto:

https://developers.google.com/protocol-buffers/docs/proto3#scalar

Samples by Google:

https://github.com/protocolbuffers/protobuf/releases/tag/v3.12.3

further references:

Project Descriptions:

please see application.properties files in resources folder and select a active profile "dev" or "com" to run project. you can check test methods too.

tips:

  • install "Protocol Buffer Editor" (https://plugins.jetbrains.com/plugin/14004-protocol-buffer-editor) for IntelijIDEA to detect .proto files (IntelijIDEA: File -> Settings -> Plugins -> search "Protocol Buffer Editor" and install and restart IDE.)
  • in IntelijIDEA for build stub files from proto file: view menu>tool windows>maven>start
  • BloomRPC: GUI Client for gRPC services. Inspired by Postman and GraphQL Playground BloomRPC aims to provide the simplest and most efficient developer experience for exploring and querying your gRPC services. Download at : https://github.com/uw-labs/bloomrpc/releases

Steps by Video:

IntellliJ IDEA Configurations:

  • IntelijIDEA: Help -> Edit Custom Vm Options -> add these two line:
    • -Dfile.encoding=UTF-8
    • -Dconsole.encoding=UTF-8
  • IntelijIDEA: File -> Settings -> Editor -> File Encodings-> Project Encoding: form "System default" to UTF-8. May be it affected somehow.
  • IntelijIDEA: File -> Settings -> Editor -> General -> Code Completion -> check "show the documentation popup in 500 ms"
  • IntelijIDEA: File -> Settings -> Editor -> General -> Auto Import -> check "Optimize imports on the fly (for current project)"
  • IntelijIDEA: File -> Settings -> Editor -> Color Scheme -> Color Scheme Font -> Scheme: Default -> uncheck "Show only monospaced fonts" and set font to "Tahoma"
  • IntelijIDEA: Run -> Edit Configuration -> Spring Boot -> XXXApplication -> Configuration -> Environment -> VM Options: -Dspring.profiles.active=dev
  • IntelijIDEA: Run -> Edit Configuration -> Spring Boot -> XXXApplication -> Code Coverage -> Fix the package in include box

springboot-grpc's People

Contributors

motaharinia avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.