An experiment in writing a gRPC proxy frontend for HTTP/protobuf services.
Sometimes things are written in languages which aren't well-suited to running complex, long-lived services like gRPC. Sometimes things are running in web servers and that already works really well. Sometimes those things do important work that other stuff in other platforms needs to use.
As for gRPC, it's the best RPC framework because it's a thin layer on top of HTTP2, which has lovely multiplexing, etc. etc. all in a totally standard protocol.
This project has three moving parts:
- An HTTP/1.1 server (running on Jetty) which implements a Protobuf-based hello world service. Pretending to be a bunch of well-tested, battle-hardened business logic trapped in a doofy runtime.
- A gRPC client which implements the client-side of that service, but not over HTTP/1.1. Just a bog-standard gRPC client. How ever will it talk to the HTTP/1.1 server?
- Our hero, a proxying gRPC server. When a request comes in, it reads the Protobuf message without
attempting to decode it, proxies that to the backend (passing the gRPC service/method name as
a query parameter named
method
) in aPOST
request, reads the Protobuf response from the backend server without parsing it, and proxies the response back to the gRPC client. Surprisingly, this works.
- gRPC 1.3.0
- OkHttp
- mutual TLS via OpenSSL (on macOS, run
brew install openssl apr
)
Not in its current form, hell no. This is just a proof-of-concept.
Yes. OkHttp is HTTP2-compatible, so if your weird PHP service is behind Nginx, you get free connection management, multiplexing, etc.
Copyright © 2017 Coda Hale
Distributed under the Apache License 2.0.