Demo - gRPC application
Yokai's showroom provides a gRPC demo application.
Overview
This gRPC demo application is a simple gRPC API offering a text transformation service.
It provides:
- a Yokai application container, with the gRPC server module to offer the gRPC API
- a Jaeger container to collect the application traces
Layout
This demo application is following the recommended project layout:
cmd/
: entry pointsconfigs/
: configuration filesinternal/
:interceptor/
: gRPC interceptorsservice/
: gRPC servicesbootstrap.go
: bootstrapregister.go
: dependencies registration
proto/
: protobuf definition and stubs
Makefile
This demo application provides a Makefile
:
make up # start the docker compose stack
make down # stop the docker compose stack
make logs # stream the docker compose stack logs
make fresh # refresh the docker compose stack
make stubs # generate gRPC stubs with protoc (ex: make stubs from=proto/transform.proto)
make test # run tests
make lint # run linter
Usage
Start the application
To start the application, simply run:
After a short moment, the application will offer:
localhost:50051
: application gRPC server- http://localhost:8081: application core dashboard
- http://localhost:16686: jaeger UI
Available services
This demo application provides a TransformTextService, with the following RPCs
:
RPC | Type | Description |
---|---|---|
TransformText |
unary | Transforms a given text using a given transformer |
TransformAndSplitText |
streaming | Transforms and splits a given text using a given transformer |
If no Transformer
is provided, the transformation configured in config.transform.default
will be applied.
If you update the proto definition, you can run make stubs from=proto/transform.proto
to regenerate the stubs.
This demo application also provides reflection and health check services.
Authentication
This demo application provides example authentication interceptors.
You can enable authentication in the application configuration file with config.authentication.enabled=true
.
If enabled, you need to provide the secret configured in config.authentication.secret
as context authorization
metadata.
Examples
Usage examples with gRPCurl:
- with
TransformTextService/TransformText
:
grpcurl -plaintext -d '{"text":"abc","transformer":"TRANSFORMER_UPPERCASE"}' localhost:50051 transform.TransformTextService/TransformText
{
"text": "ABC"
}
- with
TransformTextService/TransformAndSplitText
: