| title | Server Option | |||
|---|---|---|---|---|
| date | 2022-06-20 | |||
| weight | 2 | |||
| keywords |
|
|||
| description | Kitex Server Option instructions. |
Add some options when creating a server:
svr := api.NewServer(new(DemoImpl), server.WithXXX...)func WithServerBasicInfo(ebi *rpcinfo.EndpointBasicInfo) OptionSet the service infos for server, including ServiceName and customized Tags, customized Tag such as Cluster, IDC, Env, and it is no need to set Method field of EndpointBasicInfo. It is strongly recommended to configure this option, and those infos will be used for service registration.
func WithServiceAddr(addr net.Addr) OptionSet the listen address for server. Default port is 8888, you can reset the port to 9999 like this:
addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:9999")
svr := api.NewServer(new(HelloImpl), server.WithServiceAddr(addr))When local server has multiple IP addresses, you can also use this method to specify them.
⚠️ DeprecatedReason see Connection Multiplexing.
func WithMuxTransport() OptionEnable Kitex multiplexing transport feature on the server side. Client side also need to turn on this option, or it won't work. More
func WithMiddleware(mw endpoint.Middleware) OptionAdd a middleware. More
func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder, funcName ...string) OptionAdd middleware depends on the context passed in by the framework that contains runtime configuration information (the context of non-RPC calls), so that the middleware can take advantage of the framework's information when initializing.
func WithStreamOptions(opts ...server.StreamOption) OptionKitex >= v0.13.0 adds this option.
Aggregate streaming-related options such as StreamMiddleware, StreamSendMiddleware, StreamRecvMiddleware, RecvTimeout. Works for streaming methods. See StreamX Middleware.
func WithLimit(lim *limit.Option) OptionSet the throttling threshold, which allows you to set a limit on QPS and the number of connections, which uses a built-in throttling implementation that can be scaled if there is a custom throttling requirement, integrating your own throttling policy via WithConcurrencyLimiter or WithQPSLimiter.
func WithReadWriteTimeout(d time.Duration) OptionSet the server-side read and write timeout.
Note: This feature may be changed or removed in subsequent releases.
func WithExitWaitTime(timeout time.Duration) OptionSet the wait time for graceful shutdown of graceful shutdown on the server side.
func WithMaxConnIdleTime(timeout time.Duration) OptionSet the maximum amount of idle time allowed for the server-side connection to the client.
func WithStatsLevel(level stats.Level) OptionSet the stats level for the server. More
These options only works for scenarios where the transport protocol uses gRPC, with some parameter adjustments to gRPC transfers.
func WithGRPCWriteBufferSize(s uint32) OptionWithGRPCWriteBufferSize determines how much data can be batched before doing a write on the wire. The corresponding memory allocation for this buffer will be twice the size to keep syscalls low. The default value for this buffer is 32KB. Zero will disable the write buffer such that each write will be on underlying connection. Note: A Send call may not directly translate to a write. It corresponds to the WriteBufferSize ServerOption of gRPC.
func WithGRPCReadBufferSize(s uint32) OptionWithGRPCReadBufferSize lets you set the size of read buffer, this determines how much data can be read at most for one read syscall. The default value for this buffer is 32KB. Zero will disable read buffer for a connection so data framer can access the underlying conn directly. It corresponds to the ReadBufferSize ServerOption of gRPC.
func WithGRPCInitialWindowSize(s uint32) OptionWithGRPCInitialWindowSize returns a Option that sets window size for stream. The lower bound for window size is 64K and any value smaller than that will be ignored. It corresponds to the InitialWindowSize ServerOption of gRPC.
func WithGRPCInitialConnWindowSize(s uint32) OptionWithGRPCInitialConnWindowSize returns an Option that sets window size for a connection. The lower bound for window size is 64K and any value smaller than that will be ignored. It corresponds to the InitialConnWindowSize ServerOption of gRPC.
func WithGRPCKeepaliveParams(kp grpc.ServerKeepalive) OptionWithGRPCKeepaliveParams returns an Option that sets keepalive and max-age parameters for the server. It corresponds to the KeepaliveParams ServerOption of gRPC.
func WithGRPCKeepaliveEnforcementPolicy(kep grpc.EnforcementPolicy) OptionWithGRPCKeepaliveEnforcementPolicy returns an Option that sets keepalive enforcement policy for the server. It corresponds to the KeepaliveEnforcementPolicy ServerOption of gRPC.
func WithGRPCMaxConcurrentStreams(n uint32) OptionWithGRPCMaxConcurrentStreams returns an Option that will apply a limit on the number of concurrent streams to each ServerTransport. It corresponds to the MaxConcurrentStreams ServerOption of gRPC.
func WithGRPCMaxHeaderListSize(s uint32) OptionWithGRPCMaxHeaderListSize returns a ServerOption that sets the max (uncompressed) size of header list that the server is prepared to accept. It corresponds to the MaxHeaderListSize ServerOption of gRPC.
func WithSuite(suite Suite) OptionSet up a specific configuration, customize according to the scene, configure multiple options and middlewares combinations and encapsulations in the Suite. More
func WithProxy(p proxy.ReverseProxy) OptionIf the server has a proxy, such as Mesh Ingress, you can modify the listening address through this configuration to communicate with the proxy, such as in the proxy. ReverseProxy modifies to the uds address.
func WithRegistryInfo(info *registry.Info) OptionCustomize the registration information reported by the service. More
func WithGeneric(g generic.Generic) OptionSpecify the generalization call type, which needs to be used in conjunction with the generalization Client/Server. More
func WithErrorHandler(f func(error) error) OptionSet the error handler function, which is executed after the server handler is executed and before the middleware executes.
func WithACLRules(rules ...acl.RejectFunc) OptionSet ACL permission access control, which is executed before service discovery. More
func WithExitSignal(f func() <-chan error) OptionSet the server exit signal. Kitex has a built-in implementation, if you need some customization can be implemented yourself.
func WithReusePort(reuse bool) OptionSet port reuse, that is, whether to enable the underlying TCP port multiplexing mechanism.
func WithRegistry(r registry.Registry) OptionSpecify a Registry for service discovery registration reporting. More
func WithTracer(c stats.Tracer) OptionAdd an additional Tracer. More
func WithCodec(c remote.Codec) OptionSpecify a Codec for scenarios that require custom protocol. More
func WithPayloadCodec(c remote.PayloadCodec) OptionSpecifie a PayloadCodec. More
func WithMetaHandler(h remote.MetaHandler) OptionAdd a meta handler for customizing transparent information in conjunction with the transport protocol, such as service name, invocation method, machine room, cluster, env, tracerInfo. More
func WithBoundHandler(h remote.BoundHandler) OptionSet IO Bound handlers. More
func WithConcurrencyLimiter(conLimit limiter.ConcurrencyLimiter) OptionSet the concurrency limit for server.
func WithQPSLimiter(qpsLimit limiter.RateLimiter) OptionSet the QPS limit for server.
func WithLimitReporter(r limiter.LimitReporter) OptionSet LimitReporter, and when QPS throttling or connection limiting occurs, you can customize the escalation through LimitReporter.
func WithTransHandlerFactory(f remote.ServerTransHandlerFactory) OptionSet transHandlerFactory. More
func WithTransServerFactory(f remote.TransServerFactory) OptionSet transServerFactory. More
func WithDiagnosisService(ds diagnosis.Service) OptionSet diagnosis service. More