arpc

package
v0.0.0-...-037b315 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Broadcast

func Broadcast(ctx context.Context, srv, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error)

Broadcast 将 req 广播到所有的srv服务上

func Event

func Event(ctx context.Context, srv, route, uid string, cmd int32, event codec.Codec, opts ...CallOption) (err error)

Request 发送 event 到target服务, srv为服务名

func GetDiscorey

func GetDiscorey() registry.Discovery

func MustGetGrpcAddrsByName

func MustGetGrpcAddrsByName(ctx context.Context, srvName string) []string

func Notify

func Notify(ctx context.Context, target string, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error)

Notify 对某几个玩家发送通知

func NotifyAll

func NotifyAll(ctx context.Context, srv string, cmd int32, req codec.Codec, opts ...CallOption) (err error)

NotifyAll 对所有在线玩家发送通知

func Request

func Request(ctx context.Context, srv, route, uid string, cmd int32, req, rsp codec.Codec, opts ...CallOption) (err error)

Request 发送 req 到target服务, srv为服务名,如果要发送到特定地址的服务,需要带上 WithAddr(addr)这个CallOption

func SetDefaultClient

func SetDefaultClient(cli Client)

func SetDiscorey

func SetDiscorey(dis registry.Discovery)

Types

type CallInfo

type CallInfo struct {
	Target string      //必填,目标服务名,当Addr不为空时,请求根据一致性hash发送到某个服务
	UID    string      //必填,表示发送消息的玩家id,可以为空
	Route  string      //必填,用于一致性hash路由,可以为空
	Cmd    int32       //必填,请求命令字
	Req    codec.Codec //必填,请求数据
	Rsp    codec.Codec //选填,回包
	Addr   string      //选填,服务地址,当该地址不为空的时候,请求发送到该地址所在的服务, 其地址格式类似:grpc://127.0.0.1:32521
	Type   message.Type
}

type CallOption

type CallOption func(o *CallInfo)

func WithAddr

func WithAddr(addr string) CallOption

type Client

type Client interface {
	// Request 发送 req 到target服务, srv为服务名, 如果要发送到特定地址的服务,需要带上 WithAddr(addr)这个CallOption
	Request(ctx context.Context, srv, route, uid string, cmd int32, req, rsp codec.Codec, opts ...CallOption) (err error)
	// Request 发送 event 到target服务, srv为服务名
	Event(ctx context.Context, srv, route, uid string, cmd int32, event codec.Codec, opts ...CallOption) (err error)
	// Broadcast 将 req 广播到所有的srv服务上
	Broadcast(ctx context.Context, srv, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error)
	//Notify 对某几个玩家发送通知
	Notify(ctx context.Context, srv string, uid string, cmd int32, req codec.Codec, opts ...CallOption) (err error)
	//NotifyAll 对所有在线玩家发送通知
	NotifyAll(ctx context.Context, srv string, cmd int32, req codec.Codec, opts ...CallOption) (err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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