centrifugoKit

package
v3.0.901 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHttpClient deprecated added in v3.0.83

func NewHttpClient(addrs []string, apiKey string, httpClient *http.Client) (*gocent.Client, error)

NewHttpClient TODO: 待完善

Deprecated: (1)gocent依赖很久没更新了 (2)http客户端的负载均衡比较难搞,而grpc有现成的

@param addrs e.g.[]string{"http://localhost:8000/api"} @param apiKey centrifugo配置文件中的 api_key 项 @param httpClient 可以为nil(将使用默认值 httpClientKit.DefaultHttpClient)

func NewKeyAuth added in v3.0.83

func NewKeyAuth(grpcApiKey string) credentials.PerRPCCredentials

NewKeyAuth

PS: 应该将返回值作为传参,调用 grpc.WithPerRPCCredentials().

@param 对应 centrifugo 配置文件中的"grpc_api_key"

func PackToRpcResponse added in v3.0.87

func PackToRpcResponse(jsonData []byte, base64Flag bool) *proxyproto.RPCResponse

PackToRpcResponse

@param base64Flag 是否对 传参jsonData 进行base64编码?

func PackToRpcResponseWithCustomDisconnect added in v3.0.106

func PackToRpcResponseWithCustomDisconnect(code uint32, reason string) (*proxyproto.RPCResponse, error)

PackToRpcResponseWithCustomDisconnect 返回自定义断开.

Return custom disconnect

https://centrifugal.dev/docs/server/proxy#return-custom-disconnect

@param code 有效范围: [4000, 4999]

 			  	(1) [4000,4499]: 给客户端一个重新连接的建议.
			  		(a) 客户端收到后会断开连接,但会重连;
			  		(b) 不会触发前端的 disconnected 事件;
			 		(c) Code 和 Reason 可以从前端的 connecting 事件中得知.
			  	(2) [4500,4999]: terminal codes,客户端接收到它后不会重新连接.
			  		(a) 客户端收到后会断开连接,且不会重连;
			  		(b) 会触发前端的 disconnected 事件;
			  		(c) Code 和 Reason 可以从前端的 disconnected 事件中得知.

@param reason 请记住,由于WebSocket协议的限制和离心机内部协议的需要,你需要保持断开原因字符串不超过32个ASCII符号(即最大32字节)。

func PackToRpcResponseWithCustomError added in v3.0.106

func PackToRpcResponseWithCustomError(code uint32, message string, temporary bool) (*proxyproto.RPCResponse, error)

PackToRpcResponseWithCustomError 返回自定义错误.

Return custom error

https://centrifugal.dev/docs/server/proxy#return-custom-error

@param code 有效范围: [400, 1999]

func ParseToRpcRequest added in v3.0.87

func ParseToRpcRequest(ctx *gin.Context) (*proxyproto.RPCRequest, error)

ParseToRpcRequest

一般情况下: (1) centrifugo的 proxy_binary_encoding 配置为 false(默认),请求参数取 RPCRequest.Data (2) centrifugo的 proxy_binary_encoding 配置为 true,请求参数取 RPCRequest.B64Data,还需要手动base64解码一下(with base64.StdEncoding)

@return err == nil的情况下, 获取 method 使用 rpcRequest.Method

获取 data 使用rpcRequest.Data

Types

type GrpcClient added in v3.0.79

type GrpcClient struct {
	mutexKit.Mutex
	apiproto.CentrifugoApiClient
	// contains filtered or unexported fields
}

func NewGrpcClient added in v3.0.79

func NewGrpcClient(hosts []string, scheme string, grpcApiKey string) (*GrpcClient, error)

NewGrpcClient centrifugo服务的grpc客户端,支持客户端负载均衡(slb)

@param hosts centrifugo服务的grpc地址列表 e.g.[]string{"127.0.0.1:10000", "127.0.0.1:10001"} @param scheme grpc客户端负载均衡(slb)使用的scheme

(1) 可以为"",将自动生成
(2) 其中不能有大写字母
(3) 可以有: 小写字母、数字、"-"...
(4) 长度貌似有限制
(5) 不要以 数字 开头

@param grpcApiKey 对应centrifugo服务配置文件中的 "grpc_api_key"

func (*GrpcClient) BroadcastSimply added in v3.0.83

func (client *GrpcClient) BroadcastSimply(ctx context.Context, channels []string, jsonData []byte) (*apiproto.BroadcastResponse, error)

BroadcastSimply

@param data 必须是json!!!

func (*GrpcClient) Close added in v3.0.83

func (client *GrpcClient) Close() (err error)

func (*GrpcClient) PublishSimply added in v3.0.83

func (client *GrpcClient) PublishSimply(ctx context.Context, channel string, jsonData []byte) (*apiproto.PublishResponse, error)

PublishSimply

@param data 必须是json!!!

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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