gRPC
5/14/25About 2 mincomponentgRPCinterceptor
gRPC Configuration
gRPC Server Configuration
Configure gRPC server parameters in the YAML configuration file located in the configs
directory:
grpc:
port: 8282 # Listening port
httpPort: 8283 # HTTP listening port for profile and metrics
# Security parameters setting
# If type="", it means no secure connection, no need to fill in any parameters
# If type="one-way", it means server-side authentication, only "certFile" and "keyFile" fields need to be filled
# If type="two-way", it means both client and server-side authentication, all fields should be filled
serverSecure:
type: "" # Type: "", "one-way", "two-way"
caFile: "" # CA file, only effective for "two-way", absolute path
certFile: "" # Server cert file, absolute path
keyFile: "" # Server key file, absolute path
gRPC Client Configuration
Configure gRPC client connection parameters in the YAML configuration file located in the configs
directory:
grpcClient:
- name: "serverNameExample" # gRPC service name, used for service discovery
host: "127.0.0.1" # gRPC service IP, used for direct connection
port: 8282 # gRPC service port
timeout: 0 # Request timeout (s), 0 means no timeout control
registryDiscoveryType: "" # Registry and discovery type: Consul, etcd, nacos (if empty), connect to server using host and port
enableLoadBalance: true # Whether to enable load balancing
# Secure connection settings
# type="", this means no secure connection, no need to fill in any parameters
# type="one-way", means server-side authentication, only "serverName" and "certFile" fields need to be filled
# type="two-way", means both client and server-side authentication, please fill in all fields
clientSecure:
type: "" # Like: "", "one-way", "two-way"
serverName: "" # Domain name, e.g. *.foo.com
caFile: "" # Client CA file, only effective in "two-way", absolute path
certFile: "" # Client certificate file, absolute path, if secureType="one-way", please fill in the server certificate file here
keyFile: "" # Client key file, only effective in "two-way", absolute path
clientToken:
enable: false # Whether to enable token authentication
appID: "" # app id
appKey: "" # app key
Component Usage Reference:
Built-in gRPC Interceptors
Services created by sponge come with the following gRPC interceptors pre-integrated (implementation code can be found in internal/server/grpc.go
). You can choose to use them as needed (configuration for some interceptors can be adjusted through the YAML configuration file under the configs
directory).
Category | Feature List |
---|---|
Basic Functions | Logging, Request ID, Timeout, Recovery |
Security Authentication | JWT Authentication, Token Verification |
Traffic Control | Adaptive Rate Limiting, Circuit Breaker, Retry Policy |
Observability | Distributed Tracing, Metrics Collection |
Click to view gRPC Interceptor Usage Example.