Server Option

Kitex Server Option instructions.

Usage

Add some options when creating a server:

svr := api.NewServer(new(DemoImpl), server.WithXXX...)

Basic Options

WithServerBasicInfo

func WithServerBasicInfo(ebi *rpcinfo.EndpointBasicInfo) Option

Set 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.

WithServiceAddr

func WithServiceAddr(addr net.Addr) Option

Set 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.

WithMuxTransport

func WithMuxTransport() Option

Enable Kitex multiplexing transport feature on the server side. Client side also need to turn on this option, or it won’t work. More

WithMiddleware

func WithMiddleware(mw endpoint.Middleware) Option

Add a middleware. More

WithMiddlewareBuilder

func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder, funcName ...string) Option

Add 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.

WithLimit

func WithLimit(lim *limit.Option) Option

Set 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.

WithReadWriteTimeout

func WithReadWriteTimeout(d time.Duration) Option

Set the server-side read and write timeout.

Note: This feature may be changed or removed in subsequent releases.

WithExitWaitTime

func WithExitWaitTime(timeout time.Duration) Option

Set the wait time for graceful shutdown of graceful shutdown on the server side.

WithMaxConnIdleTime

func WithMaxConnIdleTime(timeout time.Duration) Option 

Set the maximum amount of idle time allowed for the server-side connection to the client.

WithStatsLevel

func WithStatsLevel(level stats.Level) Option

Set the stats level for the server. More

gRPC Options

These options only works for scenarios where the transport protocol uses gRPC, with some parameter adjustments to gRPC transfers.

WithGRPCWriteBufferSize

func WithGRPCWriteBufferSize(s uint32) Option

WithGRPCWriteBufferSize 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.

WithGRPCReadBufferSize

func WithGRPCReadBufferSize(s uint32) Option

WithGRPCReadBufferSize 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.

WithGRPCInitialWindowSize

func WithGRPCInitialWindowSize(s uint32) Option

WithGRPCInitialWindowSize 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.

WithGRPCInitialConnWindowSize

func WithGRPCInitialConnWindowSize(s uint32) Option

WithGRPCInitialConnWindowSize 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.

WithGRPCKeepaliveParams

func WithGRPCKeepaliveParams(kp grpc.ServerKeepalive) Option

WithGRPCKeepaliveParams returns an Option that sets keepalive and max-age parameters for the server. It corresponds to the KeepaliveParams ServerOption of gRPC.

WithGRPCKeepaliveEnforcementPolicy

func WithGRPCKeepaliveEnforcementPolicy(kep grpc.EnforcementPolicy) Option

WithGRPCKeepaliveEnforcementPolicy returns an Option that sets keepalive enforcement policy for the server. It corresponds to the KeepaliveEnforcementPolicy ServerOption of gRPC.

WithGRPCMaxConcurrentStreams

func WithGRPCMaxConcurrentStreams(n uint32) Option

WithGRPCMaxConcurrentStreams 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.

WithGRPCMaxHeaderListSize

func WithGRPCMaxHeaderListSize(s uint32) Option

WithGRPCMaxHeaderListSize 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.

Advanced Options

WithSuite

func WithSuite(suite Suite) Option

Set up a specific configuration, customize according to the scene, configure multiple options and middlewares combinations and encapsulations in the Suite. More

WithProxy

func WithProxy(p proxy.ReverseProxy) Option

If 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.

WithRegistryInfo

func WithRegistryInfo(info *registry.Info) Option

Customize the registration information reported by the service. More

WithGeneric

func WithGeneric(g generic.Generic) Option

Specify the generalization call type, which needs to be used in conjunction with the generalization Client/Server. More

WithErrorHandler

func WithErrorHandler(f func(error) error) Option

Set the error handler function, which is executed after the server handler is executed and before the middleware executes.

WithACLRules

func WithACLRules(rules ...acl.RejectFunc) Option

Set ACL permission access control, which is executed before service discovery. More

WithExitSignal

func WithExitSignal(f func() <-chan error) Option 

Set the server exit signal. Kitex has a built-in implementation, if you need some customization can be implemented yourself.

WithReusePort

func WithReusePort(reuse bool) Option

Set port reuse, that is, whether to enable the underlying TCP port multiplexing mechanism.

Extended Options

WithRegistry

func WithRegistry(r registry.Registry) Option

Specify a Registry for service discovery registration reporting. More

WithTracer

func WithTracer(c stats.Tracer) Option

Add an additional Tracer. More

WithCodec

func WithCodec(c remote.Codec) Option

Specify a Codec for scenarios that require custom protocol. More

WithPayloadCodec

func WithPayloadCodec(c remote.PayloadCodec) Option

Specifie a PayloadCodec. More

WithMetaHandler

func WithMetaHandler(h remote.MetaHandler) Option

Add 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

WithBoundHandler

func WithBoundHandler(h remote.BoundHandler) Option

Set IO Bound handlers. More

WithConcurrencyLimiter

func WithConcurrencyLimiter(conLimit limiter.ConcurrencyLimiter) Option

Set the concurrency limit for server.

WithQPSLimiter

func WithQPSLimiter(qpsLimit limiter.RateLimiter) Option

Set the QPS limit for server.

WithLimitReporter

func WithLimitReporter(r limiter.LimitReporter) Option

Set LimitReporter, and when QPS throttling or connection limiting occurs, you can customize the escalation through LimitReporter.

WithTransHandlerFactory

func WithTransHandlerFactory(f remote.ServerTransHandlerFactory) Option

Set transHandlerFactory. More

WithTransServerFactory

func WithTransServerFactory(f remote.TransServerFactory) Option

Set transServerFactory. More

WithDiagnosisService

func WithDiagnosisService(ds diagnosis.Service) Option

Set diagnosis service. More


Last modified January 18, 2024 : Upload volo blog (#936) (1fc8abb)