roadrunner_grpc_protobuf

View Source

Protocol Buffers for Roadrunner's gRPC, with modules generated by gpb.

Roadrunner serves gRPC through roadrunner_grpc, and leaves how messages turn into bytes to a codec. roadrunner_grpc_protobuf is the codec for Protocol Buffers: it builds a gRPC service from what a gpb module knows of it, encodes and decodes the messages with that module, and gives the module's .proto files to server reflection, so tools like grpcurl can list, describe and call your services.

Installation

Add both to your rebar.config, with rebar3_gpb_plugin to generate the gpb module from your .proto files:

{deps, [roadrunner, roadrunner_grpc_protobuf]}.

{plugins, [rebar3_gpb_plugin]}.
{gpb_opts, [
    {i, "proto"},
    {o_erl, "src"},
    {o_hrl, "include"},
    {module_name_suffix, "_pb"},
    maps,
    strings_as_binaries,
    descriptor
]}.
{provider_hooks, [{pre, [{compile, {protobuf, compile}}]}]}.

The modules gpb generates run on their own, so gpb is only needed to build them. With the maps option messages are maps; without it they are records. The descriptor option gives server reflection the .proto files, and can be left out if you do not turn reflection on.

Usage

For a helloworld.proto with:

package helloworld;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply);
}

write the methods in a module of their own, one function per method named after it in snake case (SayHello is say_hello/2):

-module(greeter).
-export([say_hello/2]).

say_hello(#{name := Name}, Stream) ->
    {reply, #{message => <<"Hello ", Name/binary>>}, Stream}.

Then build the service with roadrunner_grpc_protobuf:service/3 and put roadrunner_grpc_protobuf in codecs:

{ok, _} = roadrunner:start_listener(grpc, #{
    port => 50051,
    protocols => [http2],
    body_buffering => manual,
    routes => roadrunner_grpc:routes(#{
        services => [roadrunner_grpc_protobuf:service(helloworld_pb, ~"helloworld.Greeter", greeter)],
        codecs => [roadrunner_grpc_protobuf],
        reflection => true
    })
}).

The service name is its full gRPC name as a binary (~"helloworld.Greeter"), or its name in the gpb module as an atom: 'Greeter' with the options above, or 'helloworld.Greeter' when gpb's use_packages option is set.

service/4 takes options to name the functions another way, or to answer UNIMPLEMENTED for a method your module does not export. See the module documentation for them, and Roadrunner's gRPC guide for streaming, metadata, errors, deadlines, compression, health and reflection. With reflection => true, grpcurl -plaintext localhost:50051 list lists the service.

🚧 Status

roadrunner_grpc_protobuf is in 0.x. The core is functional and covered by tests, but the API may change between minor versions. Pin an exact version in your deps if you need stability across upgrades.

Sponsors

roadrunner_grpc_protobuf is open source and maintained on personal time. If you or your company find it useful, consider sponsoring.

I also accept coffees ☕

&quot;Buy Me A Coffee&quot;

Sponsors

Contributing

Contributions are welcome! Run rebar3 precommit before opening a pull request: it checks formatting, runs xref, hank, dialyzer, and the docs build, and runs the tests with a 100% coverage gate. ./scripts/grpc_interop.sh (it needs Go) runs gRPC's own interop client against the adapter over plaintext (h2c) and TLS, and grpcurl over plaintext. gRPC has no interop client for HTTP/3, so there is no interop run over HTTP/3.

License

Copyright (c) 2026 William Fank Thomé

roadrunner_grpc_protobuf is open-source under the Apache 2.0 License on GitHub.

See LICENSE.md for more information.