modulepackage
0.0.0-20221210071339-6d7f5147a063
Repository: https://github.com/lsg2020/go-actor.git
Documentation: pkg.go.dev
# README
go-actor
- go-actor is a lightweight message framework using actor model
初衷
- 想能在代码逻辑上方便的写无锁的同步rpc调用代码,同时又不会阻塞住其他服务对这个Actor的调用
- 一个Actor可以有多种身份,想能比较方便的分类管理Actor,分类通过Actor地址调用目标Actor
- 节点间使用多种传输方式,比如游戏玩家移动这种同步可以使用tcp实现快速通知消息丢失也不太紧要,平台奖励类的可以使用mq通知
快速开始
创建ActorSystem
ActorSystem用来分类管理Actor,调用某个Actor的时候需要基于他所在的同名ActorSystemgoactor.WithName
: 指定ActorSystem名字,同类同名goactor.WithInstanceId
: 指定节点id,同类型下唯一goactor.WithEtcd
: etcd注册地址,同类型使用同组etcdgoactor.WithTransport
: 关联传输器
system, err := goactor.NewActorSystem(
goactor.WithName("hello"),
goactor.WithInstanceId(1),
goactor.WithEtcd("http://127.0.0.1:2379"),
goactor.WithTransport(trans),
)
创建执行器
SingleGoroutine
: 单协程执行器,每个执行器同时只有一个协程在执行逻辑代码,当执行到Executer.Wait
时会让出执行权给同执行器的其他协程处理消息,自己挂起直到Executer.OnResponse
对应的session唤醒并等待其他协程让出执行权
single := &executer.SingleGoroutine{}
single.Start(context.Background(), 1)
创建协议
protobuf
- go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
- go install github.com/lsg2020/go-actor/tools/protoc-gen-gactor
- 定义协议文件例如
- 生成
protoc -I . --go_out=. --gactor_out=. *.proto
proto := protocols.NewProtobuf(1)
hello.RegisterHelloService(&HelloService{}, proto)
创建Actor
并指定个名字注册到ActorSystem
func (hello *HelloActor) OnInit(a goactor.Actor) {
hello.actor = a
hello.addr = system.Register(a, "hello")
}
goactor.NewActor(&HelloActor{}, single, goactor.ActorWithProto(proto))
TODO
- context取消的传递
- prometheus指标增加
- transport 支持多个system
# Packages
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewActor 创建一个actor,立即返回,如果需要等待创建完成可以使用 ActorWithInitCB.
No description provided by the author
No description provided by the author
No description provided by the author
NewLoopSelector 在同名的actor中顺序获取.
NewRandomSelector 在同名的actor中随机获取.
No description provided by the author
ProtoInterceptorChain 合并多个拦截器,从第一个依次嵌套执行.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
内置系统消息id.
回复消息id.
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
ActorAddr actor在每个ActorSystem中的唯一地址.
No description provided by the author
No description provided by the author
ActorSystem actor的管理器,及提供对外访问同system下的actor的机制.
No description provided by the author
DispatchMessage actor收发消息的载体,并存储一些上下文信息.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Type aliases
ActorHandle actor在节点下的地址,节点内唯一.
ActorOption actor的创建参数.
No description provided by the author
No description provided by the author
Callback actor消息回调函数.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ProtoInterceptor 收发消息拦截器接口.
No description provided by the author
SessionCancel 取消等待.