Documentation ¶
Overview ¶
Package client contains core part of Kitex client. Users should not directly use any method here other than the options and call options. Users should call NewClient in the generated code, which wraps the NewClient call in this package.
Index ¶
- func CallOptionInfoFromCtx(ctx context.Context) (res string)
- func CallOptionsFromCtx(ctx context.Context) (res []callopt.Option)
- func ClientErrorHandlerWithAddr(ctx context.Context, err error) error
- func DefaultClientErrorHandler(ctx context.Context, err error) error
- func NewCtxWithCallOptions(ctx context.Context, opts []callopt.Option) context.Context
- func WithContextMiddlewares(ctx context.Context, mws ...endpoint.Middleware) context.Context
- func WithMetaHandler(h remote.MetaHandler) client.Option
- type Client
- type ContextServiceInlineHandler
- type Option
- func WithACLRules(rules ...acl.RejectFunc) Option
- func WithBackupRequest(p *retry.BackupPolicy) Option
- func WithBoundHandler(h remote.BoundHandler) Option
- func WithCircuitBreaker(s *circuitbreak.CBSuite) Option
- func WithClientBasicInfo(ebi *rpcinfo.EndpointBasicInfo) Option
- func WithCloseCallbacks(callback func() error) Option
- func WithCodec(c remote.Codec) Option
- func WithConnMetric() Optiondeprecated
- func WithConnPool(pool remote.ConnPool) Option
- func WithConnReporterEnabled() Option
- func WithConnectTimeout(d time.Duration) Option
- func WithContextBackup(...) Option
- func WithDestService(svr string) Option
- func WithDiagnosisService(ds diagnosis.Service) Option
- func WithDialer(d remote.Dialer) Option
- func WithErrorHandler(f func(context.Context, error) error) Option
- func WithFailureRetry(p *retry.FailurePolicy) Option
- func WithFallback(fb *fallback.Policy) Option
- func WithFirstMetaHandler(h remote.MetaHandler) Option
- func WithFramedTransport() Optiondeprecated
- func WithGRPCConnPoolSize(s uint32) Option
- func WithGRPCInitialConnWindowSize(s uint32) Option
- func WithGRPCInitialWindowSize(s uint32) Option
- func WithGRPCKeepaliveParams(kp grpc.ClientKeepalive) Option
- func WithGRPCMaxHeaderListSize(s uint32) Option
- func WithGRPCReadBufferSize(s uint32) Option
- func WithGRPCTLSConfig(tlsConfig *tls.Config) Option
- func WithGRPCWriteBufferSize(s uint32) Option
- func WithGeneric(g generic.Generic) Option
- func WithHTTPConnection() Option
- func WithHTTPResolver(r http.Resolver) Option
- func WithHostPorts(hostports ...string) Option
- func WithInstanceMW(mw endpoint.Middleware) Option
- func WithLoadBalancer(lb loadbalance.Loadbalancer, opts ...*lbcache.Options) Option
- func WithLogger(logger klog.FormatLogger) Option
- func WithLongConnection(cfg connpool.IdleConfig) Option
- func WithMiddleware(mw endpoint.Middleware) Option
- func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder) Option
- func WithMixedRetry(p *retry.MixedPolicy) Option
- func WithMuxConnection(connNum int) Option
- func WithPayloadCodec(c remote.PayloadCodec) Option
- func WithProxy(p proxy.ForwardProxy) Option
- func WithRPCTimeout(d time.Duration) Option
- func WithResolver(r discovery.Resolver) Option
- func WithRetryContainer(rc *retry.Container) Option
- func WithRetryMethodPolicies(mp map[string]retry.Policy) Option
- func WithShortConnection() Option
- func WithSpecifiedResultRetry(rr *retry.ShouldResultRetry) Option
- func WithStatsLevel(level stats.Level) Option
- func WithSuite(suite Suite) Option
- func WithTag(key, val string) Option
- func WithTimeoutProvider(p rpcinfo.TimeoutProvider) Option
- func WithTracer(c stats.Tracer) Option
- func WithTransHandlerFactory(f remote.ClientTransHandlerFactory) Option
- func WithTransportProtocol(tp transport.Protocol) Option
- func WithWarmingUp(wuo *warmup.ClientOption) Option
- func WithXDSSuite(suite xds.ClientSuite) Option
- type Options
- type ServerInitialInfo
- type Streaming
- type Suite
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallOptionInfoFromCtx ¶
CallOptionInfoFromCtx retrieves the call Options debug information from the given context.
func CallOptionsFromCtx ¶
CallOptionsFromCtx retrieves call-Options from the given context.
func ClientErrorHandlerWithAddr ¶ added in v0.6.0
ClientErrorHandlerWithAddr is ErrorHandler for client, which will add remote addr info into error
func DefaultClientErrorHandler ¶ added in v0.3.3
DefaultClientErrorHandler is Default ErrorHandler for client when no ErrorHandler is specified with Option `client.WithErrorHandler`, this ErrorHandler will be injected. for thrift、KitexProtobuf, >= v0.4.0 wrap protocol error to TransError, which will be more friendly.
func NewCtxWithCallOptions ¶
NewCtxWithCallOptions returns a new context associated with the given call-Options.
func WithContextMiddlewares ¶ added in v0.4.3
WithContextMiddlewares add middlewares into current ctx Every client receive this ctx will execute the middlewares. Note that ContextMiddleware is prior to the ClientMiddleware.
func WithMetaHandler ¶
func WithMetaHandler(h remote.MetaHandler) client.Option
WithMetaHandler adds a MetaHandler.
Types ¶
type Client ¶
type Client interface {
Call(ctx context.Context, method string, request, response interface{}) error
}
Client is the core interface abstraction of kitex client. It is designed for generated codes and should not be used directly. Parameter method specifies the method of a RPC call. Request is a packing of request parameters in the actual method defined in IDL, consist of zero, one or multiple arguments. So is response to the actual result type. Response may be nil to address oneway calls.
func NewClient ¶
func NewClient(svcInfo *serviceinfo.ServiceInfo, opts ...Option) (Client, error)
NewClient creates a kitex.Client with the given ServiceInfo, it is from generated code.
func NewServiceInlineClient ¶ added in v0.6.0
func NewServiceInlineClient(svcInfo *serviceinfo.ServiceInfo, s ServerInitialInfo, opts ...Option) (Client, error)
NewServiceInlineClient creates a kitex.Client with the given ServiceInfo, it is from generated code.
type ContextServiceInlineHandler ¶ added in v0.6.0
type Option ¶
Option is the only way to config client.
func WithACLRules ¶
func WithACLRules(rules ...acl.RejectFunc) Option
WithACLRules adds ACL rules. Note that the ACL checking process happens before service discovery.
func WithBackupRequest ¶
func WithBackupRequest(p *retry.BackupPolicy) Option
WithBackupRequest sets the backup request policy for client, it will take effect for all methods.
func WithBoundHandler ¶
func WithBoundHandler(h remote.BoundHandler) Option
WithBoundHandler adds remote.BoundHandler for client.
func WithCircuitBreaker ¶ added in v0.0.5
func WithCircuitBreaker(s *circuitbreak.CBSuite) Option
WithCircuitBreaker adds a circuitbreaker suite for the client.
func WithClientBasicInfo ¶
func WithClientBasicInfo(ebi *rpcinfo.EndpointBasicInfo) Option
WithClientBasicInfo provides initial information for client endpoint in RPCInfo.
func WithCloseCallbacks ¶
WithCloseCallbacks adds callback to Close
func WithConnMetric
deprecated
func WithConnMetric() Option
WithConnMetric to enable reporting connection pool stats.
Deprecated: Use WithConnReporterEnabled instead.
func WithConnPool ¶
WithConnPool sets the connection pool. Note that this option can only be specified once. If more than one pool is specified by this option, only the first one will be used.
func WithConnReporterEnabled ¶
func WithConnReporterEnabled() Option
WithConnReporterEnabled to enable reporting connection pool stats.
func WithConnectTimeout ¶
WithConnectTimeout specifies the connection timeout.
func WithContextBackup ¶ added in v0.7.0
func WithContextBackup(backupHandler func(prev, cur context.Context) (ctx context.Context, backup bool)) Option
WithContextBackup enables local-session to retrieve context backuped by server, in case of user don't correctly pass context into next RPC call.
- backupHandler pass a handler to check and handler user-defined key-values according to current context, returning backup==false means no need further operations.
func WithDestService ¶
WithDestService specifies the name of target service.
func WithDiagnosisService ¶
WithDiagnosisService sets the diagnosis service for gathering debug information.
func WithDialer ¶
WithDialer sets the Dialer for creating connections.
func WithErrorHandler ¶
WithErrorHandler sets the error handler.
func WithFailureRetry ¶
func WithFailureRetry(p *retry.FailurePolicy) Option
WithFailureRetry sets the failure retry policy for client, it will take effect for all methods.
func WithFallback ¶ added in v0.5.0
WithFallback is used to set the fallback policy for the client. Demos are provided below:
demo1. fallback for error and resp `client.WithFallback(fallback.NewFallbackPolicy(yourFBFunc))` demo2. fallback for error and enable reportAsFallback, which sets reportAsFallback to be true and will do report(metric) as Fallback result `client.WithFallback(fallback.ErrorFallback(yourErrFBFunc).EnableReportAsFallback())` demo2. fallback for rpctime and circuit breaker `client.WithFallback(fallback.TimeoutAndCBFallback(yourErrFBFunc))`
func WithFirstMetaHandler ¶
func WithFirstMetaHandler(h remote.MetaHandler) Option
WithFirstMetaHandler adds a MetaHandler.
func WithFramedTransport
deprecated
func WithFramedTransport() Option
WithFramedTransport to use framed transport
Deprecated: Use WithTransportProtocol(transport.Framed) instead.
IMPORTANT: this option will be deleted in the future!!!
func WithGRPCConnPoolSize ¶ added in v0.2.0
WithGRPCConnPoolSize sets the value for the client connection pool size. In general, you should not adjust the size of the connection pool, otherwise it may cause performance degradation. You should adjust the size according to the actual situation.
func WithGRPCInitialConnWindowSize ¶ added in v0.2.0
WithGRPCInitialConnWindowSize sets the value for initial window size on a connection of grpc. The lower bound for window size is 64K and any value smaller than that will be ignored. It corresponds to the WithInitialConnWindowSize DialOption of gRPC.
func WithGRPCInitialWindowSize ¶ added in v0.2.0
WithGRPCInitialWindowSize sets the value for initial window size on a grpc stream. The lower bound for window size is 64K and any value smaller than that will be ignored. It corresponds to the WithInitialWindowSize DialOption of gRPC.
func WithGRPCKeepaliveParams ¶ added in v0.2.0
func WithGRPCKeepaliveParams(kp grpc.ClientKeepalive) Option
WithGRPCKeepaliveParams returns a DialOption that specifies keepalive parameters for the client transport. It corresponds to the WithKeepaliveParams DialOption of gRPC.
func WithGRPCMaxHeaderListSize ¶ added in v0.2.0
WithGRPCMaxHeaderListSize returns a DialOption that specifies the maximum (uncompressed) size of header list that the client is prepared to accept. It corresponds to the WithMaxHeaderListSize DialOption 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 each 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 WithReadBufferSize DialOption of gRPC.
func WithGRPCTLSConfig ¶ added in v0.5.0
WithGRPCTLSConfig sets the TLS config for gRPC client.
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 WithWriteBufferSize DialOption of gRPC.
func WithGeneric ¶
WithGeneric set Generic type for generic call
func WithHTTPConnection ¶
func WithHTTPConnection() Option
WithHTTPConnection specifies client use RPC over http.
func WithHTTPResolver ¶
WithHTTPResolver specifies resolver for url (which specified by WithURL).
func WithHostPorts ¶
WithHostPorts specifies the target instance addresses when doing service discovery. It overwrites the results from the Resolver.
func WithInstanceMW ¶
func WithInstanceMW(mw endpoint.Middleware) Option
WithInstanceMW adds middleware for client to handle request after service discovery and loadbalance process.
func WithLoadBalancer ¶
func WithLoadBalancer(lb loadbalance.Loadbalancer, opts ...*lbcache.Options) Option
WithLoadBalancer sets the loadbalancer for client.
func WithLogger ¶
func WithLogger(logger klog.FormatLogger) Option
WithLogger sets the Logger for kitex client. Deprecated: client uses the global klog.DefaultLogger.
func WithLongConnection ¶
func WithLongConnection(cfg connpool.IdleConfig) Option
WithLongConnection enables long connection with kitex's built-in pooling implementation.
func WithMiddleware ¶
func WithMiddleware(mw endpoint.Middleware) Option
WithMiddleware adds middleware for client to handle request.
func WithMiddlewareBuilder ¶
func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder) Option
WithMiddlewareBuilder adds middleware that depend on context for client to handle request
func WithMixedRetry ¶ added in v0.11.0
func WithMixedRetry(p *retry.MixedPolicy) Option
WithMixedRetry sets the mixed retry policy for client, it will take effect for all methods.
func WithMuxConnection ¶
WithMuxConnection 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 WithProxy ¶
func WithProxy(p proxy.ForwardProxy) Option
WithProxy sets the forward Proxy for client.
func WithRPCTimeout ¶
WithRPCTimeout specifies the RPC timeout.
func WithResolver ¶
WithResolver provides the Resolver for kitex client.
func WithRetryContainer ¶
WithRetryContainer sets Container
func WithRetryMethodPolicies ¶ added in v0.4.0
WithRetryMethodPolicies sets the retry policy for method. The priority is higher than WithFailureRetry and WithBackupRequest. Only the methods which are not included by this config will use the policy that is configured by WithFailureRetry or WithBackupRequest . FailureRetry and BackupRequest can be set for different method at same time. Notice: method name is case-sensitive, it should be same with the definition in IDL.
func WithShortConnection ¶ added in v0.0.2
func WithShortConnection() Option
WithShortConnection forces kitex to close connection after each call is finished.
func WithSpecifiedResultRetry ¶ added in v0.4.0
func WithSpecifiedResultRetry(rr *retry.ShouldResultRetry) Option
WithSpecifiedResultRetry is used with FailureRetry. When you enable FailureRetry and want to retry with the specified error or response, you can configure this Option. ShouldResultRetry is defined inside retry.FailurePolicy, so WithFailureRetry also can set ShouldResultRetry. But if your retry policy is enabled by remote config, WithSpecifiedResultRetry is useful.
func WithStatsLevel ¶
WithStatsLevel sets the stats level for client.
func WithTimeoutProvider ¶ added in v0.0.5
func WithTimeoutProvider(p rpcinfo.TimeoutProvider) Option
WithTimeoutProvider adds a TimeoutProvider to the client. Note that the timeout settings provided by the TimeoutProvider will be applied before the other timeout options in this package and those in the callopt package. Thus it can not modify the timeouts set by WithRPCTimeout or WithConnectTimeout.
func WithTransHandlerFactory ¶
func WithTransHandlerFactory(f remote.ClientTransHandlerFactory) Option
WithTransHandlerFactory sets the TransHandlerFactory for client.
func WithTransportProtocol ¶
WithTransportProtocol sets the transport protocol for client.
func WithWarmingUp ¶ added in v0.3.0
func WithWarmingUp(wuo *warmup.ClientOption) Option
WithWarmingUp forces the client to do some warm-ups at the end of the initialization.
func WithXDSSuite ¶ added in v0.4.0
func WithXDSSuite(suite xds.ClientSuite) Option
WithXDSSuite is used to set the xds suite for the client.
type ServerInitialInfo ¶ added in v0.6.0
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package callopt contains options that control the behavior of client on request level.
|
Package callopt contains options that control the behavior of client on request level. |
Package genericclient ...
|
Package genericclient ... |