百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

protoactor-go

> 数据库
开源

Proto Actor - 适用于 Go、C# 和 Java/Kotlin 的超快分布式行为者

5.5K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Proto Actor - 适用于 Go、C# 和 Java/Kotlin 的超快分布式行为者

### [Join our Slack channel](https://join.slack.com/t/asynkron/shared_invite/zt-ko824601-yGN1d3GHF9jzZX2VtONodQ) # Cross platform actors Introducing cross platform actor support between Go and C#. Can I use this? The Go implementation is still in beta, there are users using Proto Actor for Go in production already. But be aware that the API might change over time until 1.0. ## Sourcecode - Go This is the Go repository for Proto Actor. The C# implementation can be found here [https://github.com/asynkron/protoactor-dotnet](https://github.com/asynkron/protoactor-dotnet) ## Design principles: **Minimalistic API** - The API should be small and easy to use. Avoid enterprisey JVM like containers and configurations. **Build on existing technologies** - There are already a lot of great tech for e.g. networking and clustering, build on those. e.g. gRPC streams for networking, Consul.IO for clustering. **Pass data, not objects** - Serialization is an explicit concern, don't try to hide it. Protobuf all the way. **Be fast** - Do not trade performance for magic API trickery. Ultra fast remoting, Proto Actor currently manages to pass over **two million messages per second** between nodes using only two actors, while still preserving message order! This is six times more the new super advanced UDP based Artery transport for Scala Akka, and 30 times faster than Akka.NET. ``` … ``` ## History As the creator of the Akka.NET project, I have come to some distinct conclusions while being involved in that project. In Akka.NET we created our own thread pool, our own networking layer, our own serialization support, our own configuration support etc. etc. This was all fun and challenging, it is however now my firm opinion that this is the wrong way to go about things. **If possible, software should be composed, not built**, only add code to glue existing pieces together. This yields a much better time to market, and allows us to focus on solving the actual problem at hand, in this case concurrency and distributed programming. Proto Actor builds on existing technologies, Protobuf for serialization, gRPC streams for network transport. This ensures cross platform compatibility, network protocol version tolerance and battle proven stability. Another extremely important factor here is business agility and having an exit strategy. By being cross platform, your organization is no longer tied into a specific platform, if you are migrating from .NET to Go, This can be done while still allowing actor based services to communicate between platforms. Reinvent by not reinventing. --- ## Why Actors - Decoupled Concurrency - Distributed by default - Fault tolerance For a more indepth description of the differences, see this thread [Actors vs. CSP](https://www.quora.com/Go-programming-language-How-are-Akka-actors-are-different-than-Goroutines-and-Channels) ## Building You need to ensure that your `$GOPATH` variable is properly set. Next, install the [standard protocol buffer implementation](https://github.com/google/protobuf) and run the following commands to get all the necessary tooling: ``` go get github.com/asynkron/protoactor-go/... cd $GOPATH/src/github.com/asynkron/protoactor-go go get ./... make ``` After invoking last command you will have generated protobuf definitions and built the project. Windows users can use Cygwin to run make: [www.cygwin.com](https://www.cygwin.com/) ## Testing This command exectutes all tests in the repository except for consul integration tests (you need consul for running those tests). We also skip directories that don't contain any tests. ``` go test `go list ./... | grep -v "/examples/" | grep -v "/persistence" | grep -v "/scheduler"` ``` ## Hello world ```go type Hello struct{ Who string } type HelloActor struct{} func (state *HelloActor) Receive(context actor.Context) { switch msg := context.Message().(type) { case Hello: fmt.Printf("Hello %v\n", msg.Who) } } func main() { context := actor.EmptyRootContext props := actor.PropsFromProducer(func() actor.Actor { return &HelloActor{} }) pid, err := context.Spawn(props) if err != nil { panic(err) } context.Send(pid, Hello{Who: "Roger"}) console.ReadLine() } ``` ## State machines / SetBehavior, PushBehavior and PopBehavior ``` … ``` ## Lifecycle events Unlike Akka, Proto Actor uses messages for lifecycle events instead of OOP method overrides ``` … ``` ## Supervision Root actors are supervised by the `actor.DefaultSupervisionStrategy()`, which always issues a `actor.RestartDirective` for failing actors Child actors are supervised by their parents. Parents can customize their child supervisor strategy using `Proto Actor.Props` ### Example ``` … ``` ## Networking / Remoting Proto Actor's networking layer is built as a thin wrapper ontop of gRPC and message serialization is built on Protocol Buffers
### Example #### Node 1 ``` … ``` #### Node 2 ```go type MyActor struct{} func (*MyActor) Receive(context actor.Context) { switch msg := context.Message().(type) { case *messages.Echo: context.Send(msg.Sender, &messages.Response{ SomeValue: "result", }) } } func main() { remote.Start("localhost:8091") // register a name for our local actor so that it can be spawned remotely remote.Register("hello", actor.PropsFromProducer(func() actor.Actor { return &MyActor{} })) console.ReadLine() } ``` ### Message Contracts ```proto syntax = "proto3"; package messages; import "actor.proto"; // we need to import actor.proto, so our messages can include PID's // this is the message the actor on node 1 will send to the remote actor on node 2 message Echo { actor.PID Sender = 1; // this is the PID the remote actor should reply to string Message = 2; } // this is the message the remote actor should reply with message Response { string SomeValue = 1; } ``` Notice: always use "gogoslick_out" instead of "go_out" when generating proto code. "gogoslick_out" will create type names which will be used during serialization. For more examples, see the example folder in this repository. ## Contributors Made with [contributors-img](https://contributors-img.web.app).

GitHub Issues· 0 开放

在 GitHub 查看全部

暂无开放 Issues,或尚未同步最近议题。

核心特点

  • •Decoupled Concurrency
  • •Distributed by default
  • •Fault tolerance

> 标签

Goactor-modelactorsakkaclustering

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库