Skip to content

Files

Latest commit

 

History

History

helloworld

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

GrpcReflection helloworld

This example is mostly copied directly from grpc-elixir, with the exception that this example has:

  1. Compiled protos with descriptors on. This is required for the reflection service to run correctly
  2. Is running the GrpcReflection.Server.V1 server in its endpoint
  3. Configured the GrpcReflection.Server.V1 to include helloworld in its services

Usage

  1. Install deps and compile
$ mix do deps.get, compile
  1. Compile protos
$ ./generate_protos.sh
  1. Run the server
$ mix run --no-halt
  1. Run the client script
$ mix run priv/client.exs
  1. 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
>

Regenerate Elixir code from proto

  1. Modify the proto priv/protos/helloworld.proto
  2. Install protoc here
  3. Install protoc-gen-elixir
mix escript.install hex protobuf
  1. Generate the code:
$ ./generate_protos.sh

Refer to protobuf-elixir for more information.

How to start server when starting your application?

Pass start_server: true as an option for the GRPC.Server.Supervisor in your supervision tree.