This example is mostly copied directly from grpc-elixir
, with the exception that this example has:
- Compiled protos with descriptors on. This is required for the reflection service to run correctly
- Is running the
GrpcReflection.Server.V1
server in its endpoint - Configured the
GrpcReflection.Server.V1
to includehelloworld
in its services
- Install deps and compile
$ mix do deps.get, compile
- Compile protos
$ ./generate_protos.sh
- Run the server
$ mix run --no-halt
- Run the client script
$ mix run priv/client.exs
- Explore the reflection services
$ grpcurl -v -plaintext 127.0.0.1:50051 list
helloworld.Greeter
$ grpcurl -v -plaintext 127.0.0.1:50051 list helloworld.Greeter
helloworld.Greeter.SayHello
$ grpcurl -v -plaintext 127.0.0.1:50051 describe helloworld.Greeter.SayHello
helloworld.Greeter.SayHello is a method:
rpc SayHello ( .helloworld.HelloRequest ) returns ( .helloworld.HelloReply );
$ grpcurl -v -plaintext 127.0.0.1:50051 describe .helloworld.HelloReply
helloworld.HelloReply is a message:
message HelloReply {
optional string message = 1;
optional .google.protobuf.Timestamp today = 2;
}
$ grpcurl -plaintext -format text -d 'name: "faker"' localhost:50051 helloworld.Greeter.SayHello
message: "Hello faker"
today: <
seconds:1708412184 nanos:671267628
>
- Modify the proto
priv/protos/helloworld.proto
- Install
protoc
here - Install
protoc-gen-elixir
mix escript.install hex protobuf
- Generate the code:
$ ./generate_protos.sh
Refer to protobuf-elixir for more information.
Pass start_server: true
as an option for the GRPC.Server.Supervisor
in your supervision tree.