Documentation ¶
Overview ¶
Package server defines the Options of server
Package server .
Index ¶
- func RegisterShutdownHook(h func())
- func RegisterStartHook(h func())
- type Hooks
- type InvokeCaller
- type Invoker
- type Option
- func WithACLRules(rules ...acl.RejectFunc) Option
- func WithBoundHandler(h remote.BoundHandler) Option
- func WithCodec(c remote.Codec) Option
- func WithCompatibleMiddlewareForUnary() Option
- func WithConcurrencyLimiter(conLimit limiter.ConcurrencyLimiter) Optiondeprecated
- func WithConnectionLimiter(conLimit limiter.ConcurrencyLimiter) Option
- func WithContextBackup(enable, async bool) Option
- func WithDiagnosisService(ds diagnosis.Service) Option
- func WithEnableContextTimeout(enable bool) Option
- func WithErrorHandler(f func(context.Context, error) error) Option
- func WithExitSignal(f func() <-chan error) Option
- func WithExitWaitTime(timeout time.Duration) Option
- func WithGRPCInitialConnWindowSize(s uint32) Option
- func WithGRPCInitialWindowSize(s uint32) Option
- func WithGRPCKeepaliveEnforcementPolicy(kep grpc.EnforcementPolicy) Option
- func WithGRPCKeepaliveParams(kp grpc.ServerKeepalive) Option
- func WithGRPCMaxConcurrentStreams(n uint32) Option
- func WithGRPCMaxHeaderListSize(s uint32) Option
- func WithGRPCReadBufferSize(s uint32) Option
- func WithGRPCUnknownServiceHandler(f func(ctx context.Context, methodName string, stream streaming.Stream) error) Option
- func WithGRPCWriteBufferSize(s uint32) Option
- func WithGeneric(g generic.Generic) Option
- func WithLimit(lim *limit.Option) Option
- func WithLimitReporter(r limiter.LimitReporter) Option
- func WithListener(ln net.Listener) Option
- func WithLogger(logger klog.FormatLogger) Option
- func WithMaxConnIdleTime(timeout time.Duration) Option
- func WithMetaHandler(h remote.MetaHandler) Option
- func WithMiddleware(mw endpoint.Middleware) Option
- func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder, funcName ...string) Option
- func WithMultiProtocol() Optiondeprecated
- func WithMuxTransport() Option
- func WithPayloadCodec(c remote.PayloadCodec) Option
- func WithProfiler(pc profiler.Profiler) Option
- func WithProfilerMessageTagging(tagging remote.MessageTagging) Option
- func WithProfilerTransInfoTagging(tagging remote.TransInfoTagging) Option
- func WithProxy(p proxy.ReverseProxy) Option
- func WithQPSLimiter(qpsLimit limiter.RateLimiter) Option
- func WithReadWriteTimeout(d time.Duration) Option
- func WithRecvMiddleware(mw endpoint.RecvMiddleware) Option
- func WithRecvMiddlewareBuilder(mwb endpoint.RecvMiddlewareBuilder) Option
- func WithRefuseTrafficWithoutServiceName() Option
- func WithRegistry(r registry.Registry) Option
- func WithRegistryInfo(info *registry.Info) Option
- func WithReusePort(reuse bool) Option
- func WithSendMiddleware(mw endpoint.SendMiddleware) Option
- func WithSendMiddlewareBuilder(mwb endpoint.SendMiddlewareBuilder) Option
- func WithServerBasicInfo(ebi *rpcinfo.EndpointBasicInfo) Option
- func WithServiceAddr(addr net.Addr) Option
- func WithStatsLevel(level stats.Level) Option
- func WithSuite(suite Suite) Option
- func WithSupportedTransportsFunc(f func(option remote.ServerOption) []string) Option
- func WithTracer(c stats.Tracer) Option
- func WithTransHandlerFactory(f remote.ServerTransHandlerFactory) Option
- func WithTransServerFactory(f remote.TransServerFactory) Option
- type Options
- type RegisterOption
- type RegisterOptions
- type Server
- type Suite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterShutdownHook ¶
func RegisterShutdownHook(h func())
RegisterShutdownHook add hook which is executed after the server shutdown.
func RegisterStartHook ¶
func RegisterStartHook(h func())
RegisterStartHook add hook which is executed after the server starts.
Types ¶
type InvokeCaller ¶
InvokeCaller is the abstraction for invoker call.
type Invoker ¶
type Invoker interface { RegisterService(svcInfo *serviceinfo.ServiceInfo, handler interface{}, opts ...RegisterOption) error Init() (err error) InvokeCaller }
Invoker is the abstraction for invoker.
type Option ¶
type Option = internal_server.Option
Option is the only way to config server.
func WithACLRules ¶
func WithACLRules(rules ...acl.RejectFunc) Option
WithACLRules sets the ACL rules.
func WithBoundHandler ¶
func WithBoundHandler(h remote.BoundHandler) Option
WithBoundHandler adds remote.BoundHandler for server.
func WithCompatibleMiddlewareForUnary ¶ added in v0.9.0
func WithCompatibleMiddlewareForUnary() Option
WithCompatibleMiddlewareForUnary allows Unary APIs to use the same middleware as non-streaming APIs For thrift unary APIs over HTTP2, it's enabled by default. For grpc(protobuf) streaming, it's disabled by default for backward compatibility, and can be enabled manually. With this option, the req/resp passed to the middleware are the real args and result; For Unary APIs requests, recv/send middlewares will be skipped (still effective for other streaming API requests)
func WithConcurrencyLimiter
deprecated
added in
v0.3.2
func WithConcurrencyLimiter(conLimit limiter.ConcurrencyLimiter) Option
Deprecated: Use WithConnectionLimiter instead.
func WithConnectionLimiter ¶ added in v0.3.3
func WithConnectionLimiter(conLimit limiter.ConcurrencyLimiter) Option
WithConnectionLimiter sets the limiter of connections. If both WithLimit and WithConnectionLimiter are called, only the latter will take effect.
func WithContextBackup ¶ added in v0.7.0
WithContextBackup enables local-session to backup kitex server's context, in case of user don't correctly pass context into next RPC call.
- enable means enable context backup
- async means backup session will propagate to children goroutines, otherwise it only works on the same goroutine handler
func WithDiagnosisService ¶
WithDiagnosisService sets the diagnosis service for gathering debug information.
func WithEnableContextTimeout ¶ added in v0.9.0
WithEnableContextTimeout enables handler timeout. Available since Kitex >= v0.9.0 If enabled, a timeout middleware will be added to the beginning of the middleware chain. The timeout value will be read from RPCInfo.Config().RPCTimeout(), which can be set by a custom MetaHandler NOTE: If there's an error (excluding BizStatusError) returned by server handler or any middleware, cancel will be called automatically.
For an opensource Kitex user, TTHeader has builtin support of timeout-passing (not enabled by default):
- Client side: add the following NewClient options for enabling TTHeader and setting the timeout to TTHeader client.WithTransportProtocol(transport.TTHeader), client.WithMetaHandler(transmeta.ClientTTHeaderHandler),
- Server side: add the following NewServer options for reading from TTHeader and enable timeout control server.WithMetaHandler(transmeta.ServerTTHeaderHandler) server.WithEnableContextTimeout(true)
For requests on GRPC transport, a deadline will be added to the context if the header 'grpc-timeout' is positive, so there's no need to use this option.
func WithErrorHandler ¶
WithErrorHandler sets the error handler.
func WithExitSignal ¶ added in v0.1.0
WithExitSignal adds ExitSignal for server.
func WithExitWaitTime ¶
WithExitWaitTime sets the wait duration for graceful shutdown.
func WithGRPCInitialConnWindowSize ¶ added in v0.2.0
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.
func WithGRPCInitialWindowSize ¶ added in v0.2.0
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.
func WithGRPCKeepaliveEnforcementPolicy ¶ added in v0.2.0
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.
func WithGRPCKeepaliveParams ¶ added in v0.2.0
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.
func WithGRPCMaxConcurrentStreams ¶ added in v0.2.0
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.
func WithGRPCMaxHeaderListSize ¶ added in v0.2.0
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.
func WithGRPCReadBufferSize ¶ added in v0.3.0
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.
func WithGRPCUnknownServiceHandler ¶ added in v0.3.3
func WithGRPCWriteBufferSize ¶ added in v0.3.0
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.
func WithGeneric ¶
WithGeneric set Generic type for generic call
func WithLimit ¶
WithLimit sets the limitation of concurrent connections or max QPS. IMPORTANT: this option is not stable, and will be changed or removed in the future!!! We don't promise compatibility for this option in future versions!!!
func WithLimitReporter ¶
func WithLimitReporter(r limiter.LimitReporter) Option
WithLimitReporter do report when server limit happen
func WithListener ¶ added in v0.4.0
WithListener sets the listener for server, the priority is higher than WithServiceAddr
func WithLogger ¶
func WithLogger(logger klog.FormatLogger) Option
WithLogger sets the Logger for kitex server. Deprecated: server uses the global klog.DefaultLogger.
func WithMaxConnIdleTime ¶
WithMaxConnIdleTime sets the max idle time on connection from clients.
func WithMetaHandler ¶
func WithMetaHandler(h remote.MetaHandler) Option
WithMetaHandler adds a MetaHandler.
func WithMiddleware ¶
func WithMiddleware(mw endpoint.Middleware) Option
WithMiddleware adds middleware for server to handle request.
func WithMiddlewareBuilder ¶
func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder, funcName ...string) Option
WithMiddlewareBuilder adds middleware that depend on context for server to handle request
func WithMultiProtocol
deprecated
func WithMultiProtocol() Option
Deprecated: Useless option now, server support multi protocols by default. IMPORTANT: this option will be deleted in the future!!!
func WithMuxTransport ¶
func WithMuxTransport() Option
WithMuxTransport specifies the transport type to be mux.
func WithPayloadCodec ¶
func WithPayloadCodec(c remote.PayloadCodec) Option
WithPayloadCodec to set a payloadCodec that handle other payload which not support by kitex
func WithProfiler ¶ added in v0.4.3
WithProfiler set a profiler to server.
func WithProfilerMessageTagging ¶ added in v0.4.3
func WithProfilerMessageTagging(tagging remote.MessageTagging) Option
WithProfilerMessageTagging set message tagging function to profiler MessageTagging extracting tags after whole decode process finished. At this stage, we can get the rpcInfo from ctx, and full complete message.
func WithProfilerTransInfoTagging ¶ added in v0.4.3
func WithProfilerTransInfoTagging(tagging remote.TransInfoTagging) Option
WithProfilerTransInfoTagging set transinfo tagging function to profiler TransInfoTagging extracting tags after TransInfo decoded but before message decoded. At this stage, we can only get msg.TransInfo() and the real message payload is not decoded yet. If upstream is not use TTHeader protocol, we can get nothing here. So if you don't very care about the accuracy of statistics, we recommend to use WithProfilerMessageTagging to extract your custom tags.
func WithProxy ¶
func WithProxy(p proxy.ReverseProxy) Option
WithProxy sets the backward Proxy for server.
func WithQPSLimiter ¶ added in v0.3.2
func WithQPSLimiter(qpsLimit limiter.RateLimiter) Option
WithQPSLimiter sets the limiter of max QPS. If both WithLimit and WithQPSLimiter are called, only the latter will take effect.
func WithReadWriteTimeout ¶
WithReadWriteTimeout sets the read/write timeout on network. IMPORTANT: this option is not stable, and will be changed or removed in the future!!! We don't promise compatibility for this option in future versions!!!
func WithRecvMiddleware ¶ added in v0.9.0
func WithRecvMiddleware(mw endpoint.RecvMiddleware) Option
WithRecvMiddleware adds middleware for server to handle response. It's used for intercepting stream.RecvMsg (called by Recv or CloseAndRecv) calls
func WithRecvMiddlewareBuilder ¶ added in v0.9.0
func WithRecvMiddlewareBuilder(mwb endpoint.RecvMiddlewareBuilder) Option
WithRecvMiddlewareBuilder adds middleware that depend on a per-server context for server to handle response
func WithRefuseTrafficWithoutServiceName ¶ added in v0.9.0
func WithRefuseTrafficWithoutServiceName() Option
WithRefuseTrafficWithoutServiceName returns an Option that only accepts traffics with service name. This is used for a server with multi services and is one of the options to avoid a server startup error when having conflicting method names between services without specifying a fallback service for the method.
func WithRegistry ¶
WithRegistry to set a Registry to register service
func WithRegistryInfo ¶
WithRegistryInfo to set Registry Info if needed. It is used to add customized info and is suggested to use with WithRegistry option.
func WithReusePort ¶ added in v0.1.0
WithReusePort sets SO_REUSEPORT on listener, it is only used with Option `WithServiceAddr`. It won't take effect when listener is specified by WithListener.
func WithSendMiddleware ¶ added in v0.9.0
func WithSendMiddleware(mw endpoint.SendMiddleware) Option
WithSendMiddleware adds middleware for server to handle request. It's used for intercepting stream.SendMsg (called by Send or SendAndClose) calls
func WithSendMiddlewareBuilder ¶ added in v0.9.0
func WithSendMiddlewareBuilder(mwb endpoint.SendMiddlewareBuilder) Option
WithSendMiddlewareBuilder adds middleware that depend on a per-server context for server to handle request
func WithServerBasicInfo ¶
func WithServerBasicInfo(ebi *rpcinfo.EndpointBasicInfo) Option
WithServerBasicInfo provides initial information for client endpoint in RPCInfo.
func WithServiceAddr ¶
WithServiceAddr sets the listen address for server.
func WithStatsLevel ¶
WithStatsLevel sets the stats level for server.
func WithSupportedTransportsFunc ¶ added in v0.3.3
func WithSupportedTransportsFunc(f func(option remote.ServerOption) []string) Option
WithSupportedTransportsFunc sets a function which converts supported transports from server option.
func WithTransHandlerFactory ¶
func WithTransHandlerFactory(f remote.ServerTransHandlerFactory) Option
WithTransHandlerFactory sets the TransHandlerFactory for server.
func WithTransServerFactory ¶
func WithTransServerFactory(f remote.TransServerFactory) Option
WithTransServerFactory sets the TransServerFactory for server.
type RegisterOption ¶ added in v0.9.0
type RegisterOption = internal_server.RegisterOption
RegisterOption is the only way to config service registration.
func WithFallbackService ¶ added in v0.9.0
func WithFallbackService() RegisterOption
type RegisterOptions ¶ added in v0.9.0
type RegisterOptions = internal_server.RegisterOptions
RegisterOptions is used to config service registration.
type Server ¶
type Server interface { RegisterService(svcInfo *serviceinfo.ServiceInfo, handler interface{}, opts ...RegisterOption) error GetServiceInfos() map[string]*serviceinfo.ServiceInfo Run() error Stop() error }
Server is an abstraction of an RPC server. It accepts connections and dispatches them to the service registered to it.