Set Router is used to set canary identifiers for specific requests.
Specify the set node to forward requests to. Note: There are limitations to the set mechanism itself. Enabling set routing will disable proximity-based routing, so careful evaluation is needed.
Uses the WithCalleeSetName
options operation in tRPC-Go. Note that if the set node cannot be obtained, an empty node list will be returned, indicating a failed addressing.
- Configure the client in the
router.yaml
file. To make cross-environment calls, setdisable_servicerouter
totrue
. - Configure the
set_name
in the corresponding interface or client.
- Add the import statement
import (
_ "trpc.group/trpc-go/trpc-gateway/plugin/polaris/setrouter"
)
- tRPC framework configuration file, enable the canaryrouter interceptor.
Note: Make sure to register it in server.service.filter, not server.filter.
global: # Global configuration
server: # Server configuration
filter: # Interceptor list for all service handlers
service: # Business services provided, can have multiple
- name: trpc.inews.trpc.gateway # Service routing name
filter:
- setrouter: # Gateway plugin registered in the service filter, allowing dynamic loading in router.yaml
plugins: # Plugin configuration
log: # Log configuration
gateway: # Plugin type is gateway
setrouter: # Set Router plugin
Plugins at different levels will only be executed once, with the priority order: Router plugin > Service plugin > Global plugin
router: # Router configuration
- method: /v1/user/info
id: "xxxxxx"
target_service:
- service: trpc.user.service
plugins:
- name: setrouter
props:
set_name: set.tj.1
client: # Upstream service configuration, follows the trpc protocol
- name: trpc.user.service
plugins:
- name: setrouter
props:
set_name: set.tj.1
plugins: