All Projects → blandinw → ocaml-grpc-envoy

blandinw / ocaml-grpc-envoy

Licence: Apache-2.0 license
Using OCaml + gRPC via Envoy

Programming Languages

ocaml
1615 projects

Projects that are alternatives of or similar to ocaml-grpc-envoy

neofs-api-go
NeoFS API Golang repository contains implementation of core NeoFS structures that can be used for integration with NeoFS.
Stars: ✭ 14 (-65.85%)
Mutual labels:  protobuf, grpc
protoc-plugin
A protoc compiler plugin for Clojure applications
Stars: ✭ 28 (-31.71%)
Mutual labels:  protobuf, grpc
compatip
A simple tool to ensure compatibility between microservices
Stars: ✭ 13 (-68.29%)
Mutual labels:  protobuf, grpc
Istio Micro
istio 微服务示例代码 grpc+protobuf+echo+websocket+mysql+redis+kafka+docker-compose
Stars: ✭ 194 (+373.17%)
Mutual labels:  protobuf, grpc
agentgo
Hi! Agentgo is a tool for making remote command executions from server to client with golang, protocol buffers (protobuf) and grpc.
Stars: ✭ 15 (-63.41%)
Mutual labels:  protobuf, grpc
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (+402.44%)
Mutual labels:  protobuf, grpc
modern-api-management
A modern approach to manage APIs effectively using Protobuf
Stars: ✭ 36 (-12.2%)
Mutual labels:  protobuf, grpc
Rules proto
Modern bazel build rules for protobuf / gRPC
Stars: ✭ 179 (+336.59%)
Mutual labels:  protobuf, grpc
grphp
PHP gRPC Framework
Stars: ✭ 19 (-53.66%)
Mutual labels:  protobuf, grpc
protoactor-go
Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
Stars: ✭ 4,138 (+9992.68%)
Mutual labels:  protobuf, grpc
Grpc Kotlin
gRPC with Kotlin Coroutines
Stars: ✭ 190 (+363.41%)
Mutual labels:  protobuf, grpc
sisyphus
Sisyphus is the way how we provide backend services.
Stars: ✭ 59 (+43.9%)
Mutual labels:  protobuf, grpc
Buildbuddy
BuildBuddy is an open source Bazel build event viewer, result store, and remote cache.
Stars: ✭ 182 (+343.9%)
Mutual labels:  protobuf, grpc
Clay
Proto-first minimal server platform for gRPС+REST+Swagger APIs
Stars: ✭ 212 (+417.07%)
Mutual labels:  protobuf, grpc
Go Grpc Examples
This repo contains examples and implementations of different types of GRPC services and APIs using Golang.
Stars: ✭ 180 (+339.02%)
Mutual labels:  protobuf, grpc
qtprotobuf
Protobuf generator and bindings for Qt framework
Stars: ✭ 138 (+236.59%)
Mutual labels:  protobuf, grpc
Flutter Grpc Tutorial
[Tutorial] Asynchronous Flutter chat client with Go chat server which are powered by gRPC (simple and streaming)
Stars: ✭ 167 (+307.32%)
Mutual labels:  protobuf, grpc
Makeaplan public
【制定一个计划】是一个目标规划应用,通过最直接,最清晰的方式帮助你记录和追踪自己的计划,辅助你达成自己的目标。
Stars: ✭ 174 (+324.39%)
Mutual labels:  protobuf, grpc
FSharp.GrpcCodeGenerator
A protoc plugin to enable generation of F# code
Stars: ✭ 61 (+48.78%)
Mutual labels:  protobuf, grpc
grpc-jwt-spring-boot-starter
Spring boot starter for gRPC framework with JWT authorization
Stars: ✭ 24 (-41.46%)
Mutual labels:  protobuf, grpc

This project shows how to implement a gRPC server and a gRPC client using OCaml and Envoy, a very useful proxy open-sourced by Lyft and now part of the CNCF.

The idea is use Envoy to translate between HTTP/1.1 and HTTP/2 gRPC. Note that Envoy appears twice on the diagram, but it's actually the same process.

In this example, we expose a simple gRPC service written in OCaml that uses etcd to store key/value pairs. This showcases both a gRPC server and a client.

Schema

This architecture adds one process (Envoy) compared to a native gRPC implementation in OCaml. While this adds an ounce of complexity, Docker makes it easy to manage and your project will already include a great little proxy to handle load balancing, connection pooling, stats, retries and more. For instance, it is trivial to configure Envoy to load balance between many OCaml processes each running on a single core.

We use these OCaml libraries:

  • ocaml-protoc to encode and decode Protobuf request and response messages
  • httpaf to
    • serve HTTP/1.1 requests that have been translated from HTTP/2 by Envoy (gRPC server use case)
    • issue HTTP/1.1 requests that Envoy will translate to HTTP/2 before forwarding them to our gRPC service of choice (gRPC client use case)

Running the code

Tested on macOS and Linux. Requires:

  • docker to run Envoy and etcd
  • dune and opam to build our code
  • grpcurl to query our service
# create a Docker environment with Envoy and etcd
docker network create \
               --driver bridge \
               my-net

if [ $(uname) = Linux ]; then
  IP=$(ip -o addr list docker0 | grep -oe 'inet [0-9.]*/' | tr -d 'inet /')
  DOCKER_OPTS="--add-host host.docker.internal:$IP"
fi

docker run --name envoy \
           --detach \
           --rm \
           --publish 9910:9910 \
           --publish 9911:9911 \
           --publish 9912:9912 \
           --volume $PWD/envoy-proxy.yaml:/etc/envoy/envoy.yaml \
           $DOCKER_OPTS \
           --network my-net \
           --network-alias envoy.my-net \
           envoyproxy/envoy:v1.15-latest \
           --config-path /etc/envoy/envoy.yaml
           
docker run --name etcd \
           --detach \
           --rm \
           --publish 2379:2379 \
           --network my-net \
           --network-alias etcd.my-net \
           quay.io/coreos/etcd:latest \
           etcd \
           --listen-client-urls 'http://0.0.0.0:2379' \
           --advertise-client-urls 'http://etcd.my-net:2379'
           
# run our OCaml server
opam install --yes dune core_kernel httpaf httpaf-lwt-unix lwt ocaml-protoc
dune exec -- ./main.exe 9986
           
# in another terminal, you can query our OCaml server via Envoy, which in turn will query etcd via Envoy
( cd kv && \
  grpcurl --plaintext \
          --proto kv_service.proto \
          -d '{"key":"foo", "value":"bar"}' \
          localhost:9912 kv.KV/Set )
( cd kv && \
  grpcurl --plaintext \
          --proto kv_service.proto \
          -d '{"key":"foo"}' \
          localhost:9912 kv.KV/Get )

# clean up everything
docker rm --force etcd envoy
docker network rm my-net

Regenerating Protobuf code

( cd kv && ocaml-protoc -binary -ml_out ./ kv.proto )
( cd etcd && ocaml-protoc -binary -ml_out ./ etcd.proto )
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].