client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 47 Imported by: 1,189

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallOptionInfoFromCtx

func CallOptionInfoFromCtx(ctx context.Context) (res string)

CallOptionInfoFromCtx retrieves the call Options debug information from the given context.

func CallOptionsFromCtx

func CallOptionsFromCtx(ctx context.Context) (res []callopt.Option)

CallOptionsFromCtx retrieves call-Options from the given context.

func NewCtxWithCallOptions

func NewCtxWithCallOptions(ctx context.Context, opts []callopt.Option) context.Context

NewCtxWithCallOptions returns a new context associated with the given call-Options.

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.

type Option

type Option = client.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.

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

func WithCloseCallbacks(callback func() error) Option

WithCloseCallbacks adds callback to Close

func WithCodec

func WithCodec(c remote.Codec) Option

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

func WithConnMetric deprecated

func WithConnMetric() Option

WithConnMetric to enable reporting connection pool stats.

Deprecated: Use WithConnReporterEnabled instead.

func WithConnPool

func WithConnPool(pool remote.ConnPool) Option

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

func WithConnectTimeout(d time.Duration) Option

WithConnectTimeout specifies the connection timeout.

func WithDestService

func WithDestService(svr string) Option

WithDestService specifies the name of target service.

func WithDiagnosisService

func WithDiagnosisService(ds diagnosis.Service) Option

WithDiagnosisService sets the diagnosis service for gathering debug informations.

func WithDialer

func WithDialer(d remote.Dialer) Option

WithDialer sets the Dialer for creating connections.

func WithErrorHandler

func WithErrorHandler(f func(error) error) Option

WithErrorHandler sets the error handler.

func WithFailureRetry

func WithFailureRetry(p *retry.FailurePolicy) Option

WithFailureRetry sets the failure retry policy for client.

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

func WithGRPCConnPoolSize(s uint32) Option

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

func WithGRPCInitialConnWindowSize(s uint32) Option

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

func WithGRPCInitialWindowSize(s uint32) Option

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

func WithGRPCMaxHeaderListSize(s uint32) Option

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 WithGeneric

func WithGeneric(g generic.Generic) Option

WithGeneric set Generic type for generic call

func WithHTTPConnection

func WithHTTPConnection() Option

WithHTTPConnection specifies client use RPC over http.

func WithHTTPResolver

func WithHTTPResolver(r http.Resolver) Option

WithHTTPResolver specifies resolver for url (which specified by WithURL).

func WithHostPorts

func WithHostPorts(hostports ...string) Option

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 WithMuxConnection

func WithMuxConnection(connNum int) Option

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

func WithRPCTimeout(d time.Duration) Option

WithRPCTimeout specifies the RPC timeout.

func WithResolver

func WithResolver(r discovery.Resolver) Option

WithResolver provides the Resolver for kitex client.

func WithRetryContainer

func WithRetryContainer(rc *retry.Container) Option

WithRetryContainer sets Container

func WithShortConnection added in v0.0.2

func WithShortConnection() Option

WithShortConnection forces kitex to close connection after each call is finished.

func WithStatsLevel

func WithStatsLevel(level stats.Level) Option

WithStatsLevel sets the stats level for client.

func WithSuite

func WithSuite(suite Suite) Option

WithSuite adds a option suite for client.

func WithTag

func WithTag(key, val string) Option

WithTag sets the customize tag for service discovery, eg: idc, cluster.

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 WithTracer

func WithTracer(c stats.Tracer) Option

WithTracer adds a tracer to client.

func WithTransHandlerFactory

func WithTransHandlerFactory(f remote.ClientTransHandlerFactory) Option

WithTransHandlerFactory sets the TransHandlerFactory for client.

func WithTransportProtocol

func WithTransportProtocol(tp transport.Protocol) Option

WithTransportProtocol sets the transport protocol for client.

type Options

type Options = client.Options

Options is used to initialize a client.

type Streaming

type Streaming interface {
	Stream(ctx context.Context, method string, request, response interface{}) error
}

Streaming client streaming interface for code generate

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

Jump to

Keyboard shortcuts

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