SCG used as as proxy to connect gRPC-Web and back end gRPC services

Overview

gRPC-Web Spring Cloud Gateway

Build master branch codeql license

Spring Cloud Gateway 3.1.1 supports for gRPC and HTTP/2.

It is possible to use Spring Cloud Gateway to connect gRPC-Web and gRPC services. This project will show:

  • How SCG route gRPC-Web request to gRPC service without Envoy proxy.

  • How to integrate with Nacos and discover the gRPC service port.

Introduction to gRPC-Web

With gRPC-Web we can use proto to generate JS lib for web project like VUE to call gRPC services, but need a proxy like Envoy or golang proxy to transfer gRPC-Web protocol to gRPC.

Thanks to golang proxy, get the idea how to do the protocol transform , and build the Gateway request/response filters with Java.

gRPC and Spring Cloud Gateway

Please read spring-cloud-gateway-and-grpc, it shows how to use Spring Cloud Gateway gRPC-2-gRPC and JSON-2-gRPC

Getting started

To prepare the basic, please read spring-cloud-gateway-and-grpc gRPC-2-gRPC part, here we enable HTTP2 only without SSL

server:
  http2:
    enabled: true

So web project will call Spring Cloud Gateway using HTTP1.1 without SSL, and Spring Cloud Gateway talk with backend gRPC service using HTTP2 with TLS1.2

Here we trust all backend gRPC services.

spring:
  cloud:
    gateway:
      httpclient:
        ssl:
          use-insecure-trust-manager: true

The Spring Cloud Gateway Global filter RemoveHopByHopHeadersFilter will remove te and trailer which need in gRPC especially for stream.

spring:
  cloud:
    gateway:
      filter:
        remove-hop-by-hop:
          headers:
            - connection
            - keep-alive
            - transfer-encoding
            - proxy-authenticate
            - proxy-authorization
            - x-application-context
            - upgrade

Update HEADERS_REMOVED_ON_REQUEST list in yaml to skip te and trailer

As we build the protocol transform filter as Global filters, introduce a metadata grpcWeb in route , the gRPC-Web related filters will only work when the metadata grpcWeb is true.

      routes:
        - id: grpc
          metadata:
            grpcWeb: true
          uri: lb:https://greeter
          predicates:
            - Path=/Greeter/**
          filters:
            - GrpcLoadBalance=true

The GrpcLoadBalance is used to rebuild the target URI change the port to gRPC service port, as the common examples of gRPC springboot integrate with Nacos usually add spring boot web/webflux to support both REST and gRPC API.

We can use gRPC in springboot without spring boot web/webflux , but when use Nacos or other Register/Discovery services, there are additional code needed to trigger the registration.

Finally, come to protocol transform, need to decode request body decode, here use ModifyRequestBodyGatewayFilterFactory to do base64 decode , then modify the request headers.

For response part, base64 encode chunk by chunk to support the service side stream, then modify the response headers.

You might also like...

An annotation-based Java library for creating Thrift serializable types and services.

Drift Drift is an easy-to-use, annotation-based Java library for creating Thrift clients and serializable types. The client library is similar to JAX-

Dec 24, 2022

Intra is an experimental tool that allows you to test new DNS-over-HTTPS services that encrypt domain name lookups and prevent manipulation by your network

Intra Intra is an experimental tool that allows you to test new DNS-over-HTTPS services that encrypt domain name lookups and prevent manipulation by y

Jan 1, 2023

Mats3: Message-based Asynchronous Transactional Staged Stateless Services

Mats3: Message-based Asynchronous Transactional Staged Stateless Services

Dec 28, 2022

Fibers and actors for web development

COMSAT Scalable, Concurrent Web Apps Getting started Add the following Maven/Gradle dependencies: Feature Artifact Servlet integration for defining fi

Dec 23, 2022

Experimental Netty-based Java 16 application/web framework

Experimental Netty-based Java 16 application/web framework

Experimental Netty-based application/web framework. An example application can be seen here. Should I use this? Probably not! It's still incredibly ea

Feb 17, 2022

Microhttp - a fast, scalable, event-driven, self-contained Java web server

Microhttp is a fast, scalable, event-driven, self-contained Java web server that is small enough for a programmer to understand and reason about.

Dec 23, 2022

Java library for representing, parsing and encoding URNs as in RFC2141 and RFC8141

urnlib Java library for representing, parsing and encoding URNs as specified in RFC 2141 and RFC 8141. The initial URN RFC 2141 of May 1997 was supers

May 10, 2022

Pcap editing and replay tools for *NIX and Windows - Users please download source from

Tcpreplay Tcpreplay is a suite of GPLv3 licensed utilities for UNIX (and Win32 under Cygwin) operating systems for editing and replaying network traff

Dec 30, 2022

Android application allowing to sniff and inject Zigbee, Mosart and Enhanced ShockBurst packets on a Samsung Galaxy S20

Android application allowing to sniff and inject Zigbee, Mosart and Enhanced ShockBurst packets on a Samsung Galaxy S20

RadioSploit 1.0 This Android application allows to sniff and inject Zigbee, Mosart and Enhanced ShockBurst packets from a Samsung Galaxy S20 smartphon

Nov 1, 2022
Owner
null
Unconventional Java code for building web servers / services without a framework.

Unconventional Java code for building web servers / services without a framework. Think dropwizard but as a seed project instead of a framework. If this project had a theme it would be break the rules but be mindful of your decisions.

StubbornJava 227 Nov 15, 2022
VelocityControl is a BungeeControl-fork plugin enabling ChatControl Red to connect with your Velocity network.

VelocityControl is a BungeeControl-fork plugin enabling ChatControl Red to connect with your Velocity network.

Matej Pacan 10 Oct 24, 2022
A Velocity proxy plugin for Minecraft server discovery in k8s

A Velocity proxy plugin for Minecraft server discovery in k8s. All discovered servers are automatically added to the Velocity proxy.

Kryonite 9 Sep 13, 2022
A simple proxy software made for Telegram. Works well for areas that have MTProxy or Socks5 blocked.

A simple proxy software made for Telegram. Works well for areas that have MTProxy or Socks5 blocked.

null 42 Dec 19, 2022
LINE 4.1k Dec 31, 2022
The Java gRPC implementation. HTTP/2 based RPC

gRPC-Java - An RPC library and framework gRPC-Java works with JDK 7. gRPC-Java clients are supported on Android API levels 16 and up (Jelly Bean and l

grpc 10.2k Jan 1, 2023
Reactive stubs for gRPC

What is reactive-grpc? Reactive gRPC is a suite of libraries for using gRPC with Reactive Streams programming libraries. Using a protocol buffers comp

Salesforce 758 Dec 22, 2022
Book Finder application is a client-server application (gRPC) for educational purposes.

Book-Finder Book Finder application is a client-server application (gRPC) for educational purposes. Instalation These projects (Client/Server) are Mav

Mihai-Lucian Rîtan 21 Oct 27, 2022
gRPC Facade for Transactional Keyvalue Stores

lionrock An implementation agnostic client/server communication protocol (using protobuf and grpc) inspired heavily by FoundationDB (https://github.co

Clement Pang 23 Dec 8, 2022