module

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

rpc-client 模块接口文件

服务发现 模块接口文件

选举 模块接口文件

链路缓存 模块接口文件

监控 模块接口文件

消息发布订阅 模块接口文件

rpc-server 模块接口文件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler added in v1.4.0

type Handler func(*meta.Message) error

Handler 消息到达的函数句柄

type IChannel added in v1.4.0

type IChannel interface {
	// Arrived 绑定消息到达的函数句柄
	Arrived(Handler)

	// 关闭 channel 在topic 中的订阅,并退出
	Close() error
}

IChannel 信道,topic的消费队列

type IClient added in v1.4.0

type IClient interface {
	Init() error

	Close()

	// Invoke 发起一次 rpc 调用
	//
	// ctx 上下文,用于保存链路过程中的信息(主要用于分布式追踪
	//
	// target 目标服务的名称,用于获取定位到该服务的相关信息
	//
	// methon 目标服务中的方法,用于派送到目标服务的该方法中
	//
	// token 用户唯一凭据
	// 如果传入是空的值,则在路由到目标服务器时采用无状态的负载均衡方案(如随机。
	// 如果传入是用户的唯一凭据,则在路由的过程中采用有状态的负载均衡方案(默认提供的是平滑加权算法。
	// 如果在 braid 中注册了 linkcache 模块则通过 token 能保证此 token 在链路过程中选取的目标服务器是固定的。
	//
	// args 调用发送的参数
	//
	// reply 调用返回的参数
	//
	// opts 调用的可选项
	Invoke(
		ctx context.Context, target, methon, token string,
		args, reply interface{},
		opts ...interface{}) error
}

IClient rpc-client interface

type IDiscover added in v1.4.0

type IDiscover interface {
	Init() error
	Run()
	Close()
}

IDiscover discover interface

type IElector added in v1.4.0

type IElector interface {
	Init() error
	Run()
	Close()
}

IElector election interface

type ILinkCache added in v1.4.0

type ILinkCache interface {
	Init() error
	Run()
	Close()

	// Target 通过服务名,获取 token 指向的目标服务器地址信息
	Target(token string, serviceName string) (targetAddr string, err error)

	// Link 将 token 和目标服务器连接信息写入到缓存中
	Link(token string, target meta.Node) error

	// Unlink 将 token 和目标服务器连接信息,解除绑定关系
	Unlink(token string) error

	// Down 清理目标节点的连接信息(因为该服务已经退出
	Down(target meta.Node) error
}

ILinkCache 链路缓存,主要用于维护 token 和多个相关联的服务进程之间的关系

+---parent----------+
|                   |
|    +--child----+  |
|    |           |  |
|    | token ... |  |
|    |           |  |
|    +-----------+  |
+-------------------+

type IMonitor added in v1.4.0

type IMonitor interface {
	Run()
}

type IPubsub added in v1.4.0

type IPubsub interface {
	// Topic 获取一个 topic,如果没有则创建一个新的
	GetTopic(name string) ITopic

	// Info 输出topic的信息
	Info()
}

IPubsub 发布-订阅,管理集群中的所有 Topic

type IServer added in v1.4.0

type IServer interface {
	Init() error
	Run()
	Close()
}

IServer rpc-server interface

type ITopic added in v1.4.0

type ITopic interface {
	// Pub 向 topic 发送一条消息
	Pub(ctx context.Context, msg *meta.Message) error

	// Sub 向 topic 订阅消息
	//  注: 消费者只能保证消息必定被消费一次,但不保证消费只会被消费一次
	Sub(ctx context.Context, channelName string, opts ...interface{}) (IChannel, error)

	// Close 关闭 topic
	Close() error
}

ITopic 话题,消息对象

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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