server

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package server defines the Options of server

Package server .

Index

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 Hooks

type Hooks []func()

Hooks is a collection of func.

type InvokeCaller

type InvokeCaller interface {
	Call(invoke.Message) error
}

InvokeCaller is the abstraction for invoker call.

type Invoker

type Invoker interface {
	RegisterService(svcInfo *serviceinfo.ServiceInfo, handler interface{}) error
	Init() (err error)
	InvokeCaller
}

Invoker is the abstraction for invoker.

func NewInvoker

func NewInvoker(opts ...Option) Invoker

NewInvoker creates new 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 WithCodec

func WithCodec(c remote.Codec) Option

WithCodec to set a codec that handle other protocols which not support by kitex

func WithConcurrencyLimiter deprecated

func WithConcurrencyLimiter(conLimit limiter.ConcurrencyLimiter) Option

Deprecated: Use WithConnectionLimiter instead.

func WithConnectionLimiter

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 WithDiagnosisService

func WithDiagnosisService(ds diagnosis.Service) Option

WithDiagnosisService sets the diagnosis service for gathering debug information.

func WithErrorHandler

func WithErrorHandler(f func(context.Context, error) error) Option

WithErrorHandler sets the error handler.

func WithExitSignal

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

WithExitSignal adds ExitSignal for server.

func WithExitWaitTime

func WithExitWaitTime(timeout time.Duration) Option

WithExitWaitTime sets the wait duration for graceful shutdown.

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

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

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

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

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

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

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

func WithGRPCUnknownServiceHandler

func WithGRPCUnknownServiceHandler(f func(ctx context.Context, methodName string, stream streaming.Stream) error) Option

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

func WithGeneric

func WithGeneric(g generic.Generic) Option

WithGeneric set Generic type for generic call

func WithLimit

func WithLimit(lim *limit.Option) Option

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

func WithListener(ln net.Listener) Option

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

func WithMaxConnIdleTime(timeout time.Duration) Option

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

func WithProfiler(pc profiler.Profiler) Option

WithProfiler set a profiler to server.

func WithProfilerMessageTagging

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

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

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

func WithReadWriteTimeout(d time.Duration) Option

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 WithRegistry

func WithRegistry(r registry.Registry) Option

WithRegistry to set a Registry to register service

func WithRegistryInfo

func WithRegistryInfo(info *registry.Info) Option

WithRegistryInfo to set Registry Info if needed. It is used to add customized info and is suggested to use with WithRegistry option.

func WithReusePort

func WithReusePort(reuse bool) Option

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 WithServerBasicInfo

func WithServerBasicInfo(ebi *rpcinfo.EndpointBasicInfo) Option

WithServerBasicInfo provides initial information for client endpoint in RPCInfo.

func WithServiceAddr

func WithServiceAddr(addr net.Addr) Option

WithServiceAddr sets the listen address for server.

func WithStatsLevel

func WithStatsLevel(level stats.Level) Option

WithStatsLevel sets the stats level for server.

func WithSuite

func WithSuite(suite Suite) Option

WithSuite adds an option suite for server.

func WithSupportedTransportsFunc

func WithSupportedTransportsFunc(f func(option remote.ServerOption) []string) Option

WithSupportedTransportsFunc sets a function which converts supported transports from server option.

func WithTracer

func WithTracer(c stats.Tracer) Option

WithTracer adds a tracer to server.

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 Options

type Options = internal_server.Options

Options is used to initialize the server.

type Server

type Server interface {
	RegisterService(svcInfo *serviceinfo.ServiceInfo, handler interface{}) error
	GetServiceInfo() *serviceinfo.ServiceInfo
	Run() error
	Stop() error
}

Server is a abstraction of a RPC server. It accepts connections and dispatches them to the service registered to it.

func NewServer

func NewServer(ops ...Option) Server

NewServer creates a server with the given Options.

type Suite

type Suite interface {
	Options() []Option
}

A Suite is a collection of Options. It is useful to assemble multiple associated Options as a single one to keep the order or presence in a desired manner.

Directories

Path Synopsis
Package genericserver ...
Package genericserver ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL