tRPC-Gateway is a business gateway framework in the tRPC ecosystem.
It has the following advantages:
- Low integration cost: It is essentially a tRPC-Go service, so it can be deployed like any other tRPC-Go service.
- Low entry barrier: It can fully reuse the tRPC ecosystem, including service governance, monitoring and alerting, protocol support, and log querying.
- Rich routing strategies: It supports various routing strategies such as exact matching, prefix matching, regular expression matching, fine-grained matching, and gray deployment.
- Strong scalability: The development threshold for gateway plugins is lowered to the level of developing a tRPC filter, allowing for quick expansion of business-specific gateway logic.
- Easy enrichment of plugin ecosystem: The development threshold for gateway plugins is low enough to easily enrich the plugin ecosystem.
In the context of cloud-native technology, business gateways have become indispensable. With the gradual adoption of the internal tRPC framework within the company, there are two solutions to meet the demands for business gateways:
1 Modifying an external open-source gateway: This solution allows for the reuse of core functions from an open-source gateway but requires significant adaptation work to fit into the tRPC ecosystem.
2 Building a business gateway within the tRPC ecosystem based on the tRPC framework: It was found that this only requires the development of gateway routing logic.
tRPC-Gateway is a business gateway developed based on solution 2.
- Create a new service repository and add the main.go file, refer to main.go main.go
- Apply for Rainbow configuration and add the router.yaml configuration file, refer to router.yaml
- Deploy the service with framework configuration, refer to trpc_go.yaml
Modify the router.yaml file to configure the forwarding of your own interfaces. For more details, see Routing Configuration
You can extend the functionality of the gateway through plugins. See Gateway Plugin Development for more details.
- CORS
- access log
- limiter
- request_transformer
- response_transformer
- batch_request
- devenv
- logreplay
- mocking
- canaryrouter
- metarouter
- setrouter
- redirect
- routercheck
- traceid
- trpcerr2body
tRPC-Gateway supports HTTP as the entry protocol and can forward to other protocols. Custom protocols can be implemented by implementing the CliProtocolHandler interface.
Supported forwarding protocols:
- http -> http
- http -> trpc
- http -> grpc
No, it doesn't support trpc -> trpc protocol forwarding because it would require writing separate plugin logic to support both HTTP and trpc protocols, which would increase complexity.
If the caller expects to use the trpc pb client for calling, you can use the http -> trpc forwarding method. There is no difference in the caller's code, except that the caller's protocol can only use http.
You can fork the project, make modifications, and initiate a merge request (MR). For more details, please consult quonliu@tencent.com