grpcsdk

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: MIT Imports: 23 Imported by: 5 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

grpcsdk

grpc的客户端sdk模板,使用它快速构造grpc的sdk

本项目只适用于go 1.18+

使用步骤

  1. 将proto文件转成go模块

    protoc -I xxx --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go_out=xxx --go-grpc_out=xxx xxx.proto"

  2. 在生成的文件中找到客户端接口(以XXXXClient命名的interface)

  3. 在生成的文件中找到服务描述对象(以XXXXX_ServiceDesc命名的变量)

  4. 使用func New[T any](factory NewGrpcClientFunc[T], desc *grpc.ServiceDesc) *SDK[T]创建一个sdk实例

  5. 使用func (c *SDK[T]) Init(opts ...optparams.Option[SDKConfig]) error通过配置初始化sdk实例

  6. 使用func (c *SDK[T]) GetClient(opts ...optparams.Option[AcquireOptions]) (T, ReleaseFunc)获取客户端对象和客户端回收函数

  7. 使用func (c *SDK[T]) NewCtx(opts ...optparams.Option[CtxOptions]) (ctx context.Context, cancel context.CancelFunc)构造请求的上下文和上下文取消函数

  8. 调用接口T规定的方法.

  9. 执行上下文取消函数

  10. 执行客户端回收函数

  11. 执行func (c *SDK[T]) Close() error关闭sdk

补充:

  • 在第四步完成后可以使用sdk.Logger打印log,这个log会带有字段"module":"grpcsdk"和"target_service": desc.ServiceName,log的其它配置会根据github.com/Golang-Tools/loggerhelper/v2的Set方法变化而变化

使用例子

package main

import (
    "io"
    "os"

    "github.com/Golang-Tools/grpcsdk"
    "xxx_pb"
    log "github.com/Golang-Tools/loggerhelper/v2"
    "google.golang.org/grpc"
    "google.golang.org/grpc/metadata"
)

func main() {
    sdk := grpcsdk.New(xxx_pb.NewTESTGOGRPCSIMPLEClient, &xxx_pb.TESTGOGRPCSIMPLE_ServiceDesc)
    sdk.Logger.Info("setup sdk ok")
    err := sdk.Init(grpcsdk.WithQueryAddresses("localhost:5000"))
    if err != nil {
        sdk.Logger.Error("sdk.Init get error", log.Dict{"err": err.Error()})
    }
    defer sdk.Close()
    sdk.Logger.Info("setup sdk init ok")
    Conn, release := sdk.GetClient()
    defer release()
    sdk.Logger.Info("setup sdk GetClient ok")
    sdk.Logger.Info("setup ok")
    //req-res
    ctx, cancel := sdk.NewCtx(sdk.WithRequestMeta(), grpcsdk.WithMeta("a", "1"), grpcsdk.WithMeta("b", "2"))
    defer cancel()

    var header, trailer metadata.MD
    req, err := Conn.Square(ctx, &xxx_pb.Message{Message: 2.0},
        grpc.Header(&header),   // will retrieve header
        grpc.Trailer(&trailer), // will retrieve trailer
    )
    if err != nil {
        sdk.Logger.Error("Square get error", log.Dict{"err": err.Error()})
        os.Exit(1)
    }
    log.Info("Square get result", log.Dict{"header": header, "req": req, "trailer": trailer})

    //req-stream
    streamctx, streamcancel := sdk.NewCtx(grpcsdk.UntilEnd())
    defer streamcancel()
    ResStream, err := Conn.RangeSquare(streamctx, &xxx_pb.Message{Message: 4.0})
    if err != nil {
        sdk.Logger.Error("RangeSquare get error", log.Dict{"err": err.Error()})
        os.Exit(1)
    }
    for {
        feature, err := ResStream.Recv()
        if err != nil {
            if err == io.EOF {
                break
            } else {
                sdk.Logger.Error("RangeSquare(_) = _", log.Dict{"err": err.Error()})
                os.Exit(1)
            }
        }
        sdk.Logger.Info("RangeSquare get res", log.Dict{"res": feature})
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is the error when the client pool is closed
	ErrClosed = errors.New("grpc pool: client pool is closed")
	// ErrTimeout is the error when the client pool timed out
	ErrTimeout = errors.New("grpc pool: client pool timed out")
	// ErrAlreadyClosed is the error when the client conn was already closed
	ErrAlreadyClosed = errors.New("grpc pool: the connection was already closed")
	// ErrFullPool is the error when the pool is already full
	ErrFullPool = errors.New("grpc pool: closing a ClientConn into a full pool")
	//ErrLimitsSmallThanReservation 初始化参数limits比reservations小
	ErrLimitsSmallThanReservation = errors.New("init param limits must larger than reservations")
	//ErrReservationSmallThanOne 初始化参数reservations比1小
	ErrReservationSmallThanOne = errors.New("init param reservation must larger than 1")
)
View Source
var DefaultNewClientOpts = NewClientOptions{
	DialOpts: []grpc.DialOption{},
}

DefaultNewClientOpts 默认新建客户端的选项

View Source
var DefaultNewClientPoolOpts = NewClientPoolOptions{
	NewClientOptions: &NewClientOptions{DialOpts: []grpc.DialOption{}},
	Reservations:     1,
	Limits:           3,
	AcquireWaitTime:  time.Duration(1) * time.Millisecond,
}

DefaultNewClientPoolOpts 默认新建客户端池的选项

Functions

func Force

UntilEnd NewCtx方法的参数,用于设置ctx为不会超时

func HasClientConfig

HasClientConfig 复用创建客户端的选项用于创建池 @params opts ...optparams.Option[NewClientOptions] 用于创建客户端的配置项

func UntilEnd

func UntilEnd() optparams.Option[CtxOptions]

UntilEnd NewCtx方法的参数,用于设置ctx为不会超时

func WithAcquireWaitTimeMS

func WithAcquireWaitTimeMS(wait int) optparams.Option[NewClientPoolOptions]

WithAcquireWaitTimeMS 创建池对象方法的参数,用于设置从连接池中获取连接的最大等待时长,单位ms. @params wait int 获取客户端等待时长

func WithAddr

func WithAddr(addr string) optparams.Option[NewClientOptions]

WithAddr 创建客户端对象方法的参数,用于设置连接地址 @params addr string 连接地址,如果是多个地址,则会做本地负载均衡后生成一个地址填入

func WithCaCertPath

func WithCaCertPath(path string) optparams.Option[SDKConfig]

WithCaCertPath sdk.Init方法的参数,用于设置sdk如果要使用tls则需要指定根证书位置 @params path string 根证书路径

func WithClientCertPath

func WithClientCertPath(path string) optparams.Option[SDKConfig]

WithClientCertPath sdk.Init方法的参数,用于设置sdk客户端证书位置 @params path string 客户端证书路径

func WithClientConfig

func WithClientConfig(conf *NewClientOptions) optparams.Option[NewClientOptions]

WithClientConfig 创建客户端对象方法的参数,用于通过NewClientOptions对象设置客户端 @params conf *NewClientOptions 设置新建客户端的选项

func WithClientKeyPath

func WithClientKeyPath(path string) optparams.Option[SDKConfig]

WithClientKeyPath sdk.Init方法的参数,用于设置sdk客户端证书对应的私钥位置 @params path string 客户端证书对应的私钥路径

func WithClientPool

func WithClientPool() optparams.Option[SDKConfig]

WithClientPool sdk.Init方法的参数,用于设置sdk是否使用grpc的客户端池

func WithClientPoolAcquireWaitTime

func WithClientPoolAcquireWaitTime(wait int) optparams.Option[SDKConfig]

WithClientPoolAcquireWaitTime sdk.Init方法的参数,用于设置sdk获取客户端池时的最大等待时间 @params wait int 获取客户端池时的最大等待时间,单位ms

func WithClientPoolLimits

func WithClientPoolLimits(n int) optparams.Option[SDKConfig]

WithClientPoolLimits sdk.Init方法的参数,用于设置sdk使用客户端池时的池最大水位 @params n int 使用客户端池时的池最大水位

func WithClientPoolReservations

func WithClientPoolReservations(n int) optparams.Option[SDKConfig]

WithClientPoolReservations sdk.Init方法的参数,用于设置sdk使用客户端池时的池注水水位 @params n int 使用客户端池时的池注水水位

func WithCompression

func WithCompression(protocol string) optparams.Option[SDKConfig]

WithCompression sdk.Init方法的参数,用于设置sdk使用哪种方式压缩发送的消息 @params protocol string 协议名,目前可选的只有gzip

func WithConfig

func WithConfig(config *SDKConfig) optparams.Option[SDKConfig]

UntilEnd NewCtx方法的参数,用于设置ctx为不会超时

func WithConnWithBlock

func WithConnWithBlock() optparams.Option[SDKConfig]

WithConnWithBlock sdk.Init方法的参数,用于设置sdk是否同步的建立连接

func WithDialOpts

func WithDialOpts(opts ...grpc.DialOption) optparams.Option[NewClientOptions]

WithDialOpts 创建客户端对象方法的参数,用于设置连接时的参数 @params opts ...grpc.DialOption grpc的拨号设置

func WithInitialConnWindowSize

func WithInitialConnWindowSize(size int) optparams.Option[SDKConfig]

WithInitialConnWindowSize sdk.Init方法的参数,用于设置sdk基于Connection的滑动窗口大小 @params size int 基于Connection的滑动窗口大小

func WithInitialWindowSize

func WithInitialWindowSize(size int) optparams.Option[SDKConfig]

WithInitialWindowSize sdk.Init方法的参数,用于设置sdk基于Stream的滑动窗口大小 @params size int 基于Stream的滑动窗口大小

func WithKeepaliveEnforcementPermitWithoutStream

func WithKeepaliveEnforcementPermitWithoutStream() optparams.Option[SDKConfig]

WithKeepaliveEnforcementPermitWithoutStream sdk.Init方法的参数,用于设置sdk是否当连接空闲时仍然发送PING帧监测

func WithKeepaliveTime

func WithKeepaliveTime(alivetime int) optparams.Option[SDKConfig]

WithKeepaliveTime sdk.Init方法的参数,用于设置sdk空闲连接每隔n秒ping一次客户端已确保连接存活 @params alivetime int 空闲连接每隔n秒ping一次客户端已确保连接存活,单位ms

func WithKeepaliveTimeout

func WithKeepaliveTimeout(timeout int) optparams.Option[SDKConfig]

WithKeepaliveTimeout sdk.Init方法的参数,用于设置sdkping时长超过n则认为连接已死 @params timeout int ping时长超过n则认为连接已死,单位ms

func WithLimits

func WithLimits(limits int) optparams.Option[NewClientPoolOptions]

WithLimits 创建池对象方法的参数,用于设置连接池的最大连接数 @params limits int 池最大水位

func WithMaxRecvMsgSize

func WithMaxRecvMsgSize(size int) optparams.Option[SDKConfig]

WithMaxRecvMsgSize sdk.Init方法的参数,用于设置sdk允许接收的最大消息长度 @params size int 允许接收的最大消息长度

func WithMaxSendMsgSize

func WithMaxSendMsgSize(size int) optparams.Option[SDKConfig]

WithMaxSendMsgSize sdk.Init方法的参数,用于设置sdk允许发送的最大消息长度 @params size int 允许发送的最大消息长度

func WithMeta

func WithMeta(key string, value ...string) optparams.Option[CtxOptions]

WithMeta NewCtx方法的参数,用于设置信息到meta数据 @params key string meta键 @params value ...string meta值

func WithQueryAddresses

func WithQueryAddresses(addresses ...string) optparams.Option[SDKConfig]

WithQueryAddresses sdk.Init方法的参数,用于设置sdk请求的地址 @params addresses ...string 连接服务的主机地址

func WithQueryTimeout

func WithQueryTimeout(timeout int) optparams.Option[SDKConfig]

WithQueryTimeout sdk.Init方法的参数,用于设置sdk请求服务的最大超时时间 @params wait int 请求服务的最大超时时间,单位ms

func WithRequesterAppName

func WithRequesterAppName(name string) optparams.Option[SDKConfig]

WithRequesterAppName sdk.Init方法的参数,用于设置sdk请求方服务名 @params name string 请求端app名

func WithRequesterAppVersion

func WithRequesterAppVersion(version string) optparams.Option[SDKConfig]

WithRequesterAppVersion sdk.Init方法的参数,用于设置sdk请求方服务版本 @params version string 请求方服务版本

func WithReservations

func WithReservations(reservations int) optparams.Option[NewClientPoolOptions]

WithReservations 创建池对象方法的参数,用于设置连接池的最小连接数 @params reservations int 池安全水位

func WithStreamInterceptors

func WithStreamInterceptors(interceptor ...grpc.StreamClientInterceptor) optparams.Option[SDKConfig]

WithStreamInterceptors sdk.Init方法的参数,用于设置sdk的流请求拦截器 @params interceptor ...grpc.StreamClientInterceptor 流请求拦截器

func WithTimeout

func WithTimeout(timeout time.Duration) optparams.Option[CtxOptions]

WithTimeout NewCtx方法的参数,用于设置ctx为指定的超时时长 @params timeout time.Duration 请求超时,单位ms

func WithUnaryInterceptors

func WithUnaryInterceptors(interceptor ...grpc.UnaryClientInterceptor) optparams.Option[SDKConfig]

WithUnaryInterceptors sdk.Init方法的参数,用于设置sdk的请求拦截器 @params interceptor ...grpc.UnaryClientInterceptor 请求拦截器

func WithXDSCREDS

func WithXDSCREDS() optparams.Option[SDKConfig]

WithXDSCREDS sdk.Init方法的参数,用于设置sdk当address的schema是xds时是否使用xds的令牌加密访问

Types

type AcquireOptions

type AcquireOptions struct {
	Force bool
}

AcquireOptions 设置Acquire方法的选项

type Client

type Client[T any] struct {
	// contains filtered or unexported fields
}

Client 客户端类,满足接口GrpcClientGetter和GrpcClientInterface @generics T any 需要指定返回的客户端接口

func NewClient

func NewClient[T any](newgrpcclientfunc NewGrpcClientFunc[T], opts ...optparams.Option[NewClientOptions]) (*Client[T], error)

NewClient 创建一个客户端对象 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params newgrpcclientfunc NewGrpcClientFunc[T] 将grpc连接转化为grpc客户端的程序,可以在pb生成的模块中找到,通常以`NewXXXXXXClient`命名 @params opts ...optparams.Option[NewClientOptions] 创建客户端的配置项,详细可以看clientnewopts.go文件 @returns *Client[T] 返回客户端对象 @returns error 错误信息

func (*Client[T]) Acquire

func (p *Client[T]) Acquire(opts ...optparams.Option[AcquireOptions]) (GrpcClientInterface[T], error)

Acquire 维持接口,返回自身 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params opts ...optparams.Option[AcquireOptions] acquire方法的参数,只有`Force()`可用,不会生效 @returns GrpcClientInterface[T] 客户端接口对象 @returns error 错误信息

func (*Client[T]) AsGrpcClient

func (c *Client[T]) AsGrpcClient() T

AsGrpcClient 将对象转成满足T接口的对象,此处返回自身 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns T 返回自身

func (*Client[T]) Close

func (c *Client[T]) Close() error

Close 断开连接 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns error 错误信息

func (*Client[T]) GetConn

func (c *Client[T]) GetConn() GrpcConnInterface

GetConn 获取客户端资源,即获取自身 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns GrpcConnInterface 返回自身

func (*Client[T]) Release

func (p *Client[T]) Release(cli GrpcClientInterface[T])

Release 释放客户端资源,维持接口不做任何操作 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params cli GrpcClientInterface[T] 要释放的客户端资源

type CtxOptions

type CtxOptions struct {
	UntilEnd bool
	Timeout  time.Duration
	MetaData metadata.MD
}

CtxOptions 设置ctx行为的选项

type GrpcClientGetter

type GrpcClientGetter[T any] interface {
	Acquire(...optparams.Option[AcquireOptions]) (GrpcClientInterface[T], error)
	Release(cli GrpcClientInterface[T])
	Close() error
}

GrpcClientGetter 客户获取客户端的对象 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface

type GrpcClientInterface

type GrpcClientInterface[T any] interface {
	GetConn() GrpcConnInterface
	AsGrpcClient() T
	Close() error
}

GrpcClientInterface grpc的客户端接口 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface

type GrpcConnInterface

type GrpcConnInterface interface {
	grpc.ClientConnInterface
	GetState() connectivity.State
	Connect()
	ResetConnectBackoff()
	Close() error
}

GrpcConnInterface grpc的连接接口

type GrpcConnPool

type GrpcConnPool[T any] struct {
	// contains filtered or unexported fields
}

GrpcConnPool 客户端连接池,满足接口GrpcClientGetter @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface

func NewPool

func NewPool[T any](newgrpcclientfunc NewGrpcClientFunc[T], opts ...optparams.Option[NewClientPoolOptions]) (*GrpcConnPool[T], error)

NewPool 创建一个池 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params newclientfunc NewGrpcClientFunc[T] 将grpc连接转化为grpc客户端的程序,可以在pb生成的模块中找到,通常以`NewXXXXXXClient`命名 @params opts ...optparams.Option[NewClientPoolOptions] 创建池对象的参数选项,详细可以看clientpoolnewopts.go文件 @returns *GrpcConnPool[T] 返回客户端连接池对象 @returns error 错误信息

func (*GrpcConnPool[T]) Acquire

func (p *GrpcConnPool[T]) Acquire(opts ...optparams.Option[AcquireOptions]) (GrpcClientInterface[T], error)

Acquire 获取客户端接口 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params opts ...optparams.Option[AcquireOptions] acquire方法的参数,只有`Force()`可用,表示是否强制获取,如果队列中已经没有可用的客户端了则创建一个客户端对象 @returns GrpcClientInterface[T] 客户端接口对象 @returns error 错误信息

func (*GrpcConnPool[T]) Available

func (p *GrpcConnPool[T]) Available() int

Available 获取当前池可用的客户端数 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns int 可用客户端数

func (*GrpcConnPool[T]) Close

func (p *GrpcConnPool[T]) Close() error

Close 关闭连接池 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns error 错误信息

func (*GrpcConnPool[T]) IsClosed

func (p *GrpcConnPool[T]) IsClosed() bool

IsClosed 监测池是否已经关闭 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns bool 是否已经关闭

func (*GrpcConnPool[T]) Limits

func (p *GrpcConnPool[T]) Limits() int

Limits 返回池最大容量限制 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns int 最大容量

func (*GrpcConnPool[T]) Release

func (p *GrpcConnPool[T]) Release(cli GrpcClientInterface[T])

Release 释放连接放回池中 关闭状态的连接不会被放入池中 当池子当前容量小于设置的最小值时才会放回,否则关闭连接 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params cli GrpcClientInterface[T] 要释放的客户端资源

type NewClientOptions

type NewClientOptions struct {
	Addr     string
	DialOpts []grpc.DialOption
}

NewClientOptions 设置新建客户端的选项

type NewClientPoolOptions

type NewClientPoolOptions struct {
	*NewClientOptions
	Reservations    int
	Limits          int
	AcquireWaitTime time.Duration
}

NewClientPoolOptions 设置新建客户端池的选项

type NewGrpcClientFunc

type NewGrpcClientFunc[T any] func(grpc.ClientConnInterface) T

NewGrpcClientFunc 用于构造可以被池使用对象的工厂函数 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface

type ReleaseFunc

type ReleaseFunc func()

type SDK

type SDK[T any] struct {
	*SDKConfig

	Logger *log.Log
	// contains filtered or unexported fields
}

SDK 的客户端类型 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface

func New

func New[T any](factory NewGrpcClientFunc[T], desc *grpc.ServiceDesc) *SDK[T]

New 创建客户端对象 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params factory NewGrpcClientFunc[T] 将grpc连接转化为grpc客户端的程序,可以在pb生成的模块中找到,通常以`NewXXXXXXClient`命名 @params desc *grpc.ServiceDesc grpc服务的描述对象,可以在pb生成的模块中找到,通常以`XXXXX_ServiceDesc`命名 @returns *SDK[T] SDK对象

func (*SDK[T]) Close

func (c *SDK[T]) Close() error

NewClientGetter 建立一个新的客户端获取器,并绑定至sdk中 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns error 错误信息

func (*SDK[T]) GetClient

func (c *SDK[T]) GetClient(opts ...optparams.Option[AcquireOptions]) (T, ReleaseFunc)

GetClient 返回接口和回收函数 注意如果获取连接时报错会报panic @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params opts ...optparams.Option[AcquireOptions] acquire方法的参数,只有`Force()`可用,表示是否强制获取,如果队列中已经没有可用的客户端了则创建一个客户端对象 @returns T grpc客户端对象 @returns ReleaseFunc grpc客户端回收函数

func (*SDK[T]) Init

func (c *SDK[T]) Init(opts ...optparams.Option[SDKConfig]) error

Init 初始化sdk客户端的连接信息 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface

func (*SDK[T]) NewClientGetter

func (c *SDK[T]) NewClientGetter() (GrpcClientGetter[T], error)

NewClientGetter 建立一个新的客户端获取器,并绑定至sdk中 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @returns GrpcClientGetter[T] 客户端获取器 @returns error 错误信息

func (*SDK[T]) NewCtx

func (c *SDK[T]) NewCtx(opts ...optparams.Option[CtxOptions]) (ctx context.Context, cancel context.CancelFunc)

NewCtx 创建请求的上下文,这个上下问可以带元数据信息 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface @params opts ...optparams.Option[CtxOptions] 构造上下文的参数 @returns ctx context.Context 上下文对象 @returns cancel context.CancelFunc 上下文取消函数

func (*SDK[T]) RegistInterceptor

func (c *SDK[T]) RegistInterceptor()

RegistInterceptor 注册拦截器

func (*SDK[T]) WithRequestMeta

func (c *SDK[T]) WithRequestMeta() optparams.Option[CtxOptions]

WithRequestMeta NewCtx方法的参数,用于设置请求端信息到meta数据 @generics T any 由pb生成的客户端接口,以`XXXXClient`命名的interface

type SDKConfig

type SDKConfig struct {
	Query_Addresses       []string `json:"query_addresses" jsonschema:"required,description=连接服务的主机地址"`
	Requester_App_Name    string   `json:"requester_app_name,omitempty" jsonschema:"description=请求方服务名"`
	Requester_App_Version string   `json:"requester_app_version,omitempty" jsonschema:"description=请求方服务版本"`

	// 性能设置
	Initial_Window_Size                         int  `json:"initial_window_size,omitempty" jsonschema:"description=基于Stream的滑动窗口大小"`
	Initial_Conn_Window_Size                    int  `json:"initial_conn_window_size,omitempty" jsonschema:"description=基于Connection的滑动窗口大小"`
	Keepalive_Time                              int  `json:"keepalive_time,omitempty" jsonschema:"description=空闲连接每隔n秒ping一次客户端已确保连接存活"`
	Keepalive_Timeout                           int  `json:"keepalive_timeout,omitempty" jsonschema:"description=ping时长超过n则认为连接已死"`
	Keepalive_Enforcement_Permit_Without_Stream bool `` /* 134-byte string literal not displayed */
	Conn_With_Block                             bool `json:"conn_with_block,omitempty" jsonschema:"description=同步的连接建立"`
	Max_Recv_Msg_Size                           int  `json:"max_rec_msg_size,omitempty" jsonschema:"description=允许接收的最大消息长度"`
	Max_Send_Msg_Size                           int  `json:"max_send_msg_size,omitempty" jsonschema:"description=允许发送的最大消息长度"`

	//压缩设置,目前只支持gzip
	Compression string `json:"compression,omitempty" jsonschema:"description=使用哪种方式压缩发送的消息,enum=gzip"`

	// TLS设置
	Ca_Cert_Path     string `json:"ca_cert_path,omitempty" jsonschema:"description=如果要使用tls则需要指定根证书位置"`
	Client_Cert_Path string `json:"client_cert_path,omitempty" jsonschema:"description=客户端证书位置"`
	Client_Key_Path  string `json:"client_key_path,omitempty" jsonschema:"description=客户端证书对应的私钥位置"`

	// XDS设置
	XDS_CREDS bool `json:"xds_creds,omitempty" jsonschema:"description=当address的schema是xds时是否使用xds的令牌加密访问"`

	//客户端连接池
	Client_Pool                      bool `json:"client_pool" jsonschema:"description=是否使用grpc的客户端池"`
	Client_Pool_Reservations         int  `json:"client_pool_reservations" jsonschema:"description=使用客户端池时的池注水水位"`
	Client_Pool_Limits               int  `json:"client_pool_limits" jsonschema:"description=使用客户端池时的池最大水位"`
	Client_Pool_Acquire_Wait_Time_MS int  `json:"client_pool_acquire_wait_time_ms" jsonschema:"description=获取客户端池时的最大等待时间"`
	// 请求超时设置
	Query_Timeout int `json:"query_timeout,omitempty" jsonschema:"description=请求服务的最大超时时间单位ms"`

	UnaryInterceptors  []grpc.UnaryClientInterceptor  `json:"-" jsonschema:"nullable"`
	StreamInterceptors []grpc.StreamClientInterceptor `json:"-" jsonschema:"nullable"`
}

SDKConfig 的客户端类型

Jump to

Keyboard shortcuts

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