Exploration of gRPC in Elixir.
We'll be using: Elixir GRPC and Protobuf-elixir
To properly develop and test the application, the following dependencies need to be installed on your machine:
-
protoc: This is required to compile .proto files. If you are using an OSX machine, you can install it by running
brew install protobuf
. For other platforms, please refer to the specific instructions. -
grpcurl: This tool allows you to interact with the application. On OSX, you can install it by running
brew install grpcurl
. For other platforms, please check the platform-specific instructions. -
protoc-gen-elixir: Run the command
mix escript.install hex protobuf
to install the protoc-gen-elixir script. Make sure it is available on your path. If you use ASDF as your runtime version manager, you need to runasdf reshim elixir
after installation.
Make sure all the dependencies are successfully installed before proceeding with the development and testing of the application.
Run mix grpc.server
to start the server.
The following should now work:
grpcurl -plaintext -proto x_grpc.proto -d '{"first_name": "Simon", "last_name": "Smith", "age": 40}' localhost:50051 x_grpc.User.Create
grpcurl -plaintext -proto x_grpc.proto -d '{"first_name": "Jane", "last_name": "Jones", "age": 45}' localhost:5001 x_grpc.User.Create
grpcurl -plaintext -proto x_grpc.proto -d '{"id": 1}' localhost:5001 x_grpc.User.Get
{
"firstName": "Simon",
"lastName": "Smith",
"age": 40
}
grpcurl -plaintext -proto x_grpc.proto -d '{"id": 2}' localhost:5001 x_grpc.User.Get
{
"firstName": "Jane",
"lastName": "Jones",
"age": 45
}
The following will produce an error:
grpcurl -plaintext -proto x_grpc.proto -d '{"id": 3}' localhost:5001 x_grpc.User.Get
ERROR:
Code: NotFound
Message: Some requested entity (e.g., file or directory) was not found