-
Notifications
You must be signed in to change notification settings - Fork 0
gRPC Support
This document contains details about adding gRPC transport support for Mashling.
gRPC is a modern, open source remote procedure call (RPC) framework that can run anywhere. It enables client and server applications to communicate transparently, and makes it easier to build connected systems.
In gRPC a client application can directly call methods on a server application on a different machine as if it was a local object, making it easier for you to create distributed applications and services. As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. On the server side, the server implements this interface and runs a gRPC server to handle client calls. On the client side, the client has a stub (referred to as just a client in some languages) that provides the same methods as the server.
Mashling internally uses gRPC concepts and provides a trigger which will route to different dispatches based on method name.
Develop a generic gRPC trigger and CLI tool which will accept any proto file and generate available methods to use in dispatch section in gateway.json file.
.proto → Input file to CLI tool which will produce stub file(.pb.go) and service file(.grpcservice.go)
.pb.go → Auto generated file by CLI tool which in tern uses protoc binary.
.grpcservice.go → Auto generated file by CLI tool which holds method implementation logic and response mapping code.
trigger.json → Json file contains metadata for gRPC trigger
trigger.go → gRPC trigger file which will serve on given port and registers gRPC service registry.
grpcServiceRegistry.go → Registry file contains self registration logic which should be used by .grpcservice.go.
Overall Process:
-
Include gRPC trigger inside mashling gateway binary.
-
Capability to route method calls to appropriate dispatch services mentioned in gateway json.
-
Provision for user to write his own logic to transform and respond to client needs based on response from dispatch service.
-
Auto-Code generation component to generate proto files from defined IDL(*.proto file) and implementation code file to support trigger.
NOTE: For now mashling supports only unary method implementations.
-
Gateway File:
A. gateway file should contain port number field.
B. ssl/tls configurable fields for cert and key file paths.
C. dispatch settings to include method name for routing.Sample json looks like:
-
Trigger:
A. Serve on specified port by applying ssl/tls as per the gateway.json file
B. Trigger should be independent of gRPC server method implementation and should provide service register logic to register implemented methods on grpc server.
C. Handling tracing and graceful shutting of server. -
Auto-Code Generation Tool:
Tool should address two things. First, by taking proto file(IDL *.proto) tool should generate golang supported stub files. Second, tool should create server interface method implementation code that contain logic to dispatch specific handler, Based on the data arrived from dispatch service user has to write his own logic for transforming response data to client needs.
- Download mashling from github.
- Manually download protoc binary and configure it in PATH env variable.
- Generate gRPC support files using mashling-cli.exe file by passing proto file to cli tool.
- User can edit the generated file if he wants to map response to client needs. Generated files are available in trigger path.
- Build and Run the gateway.
Flow Diagram: