github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/prepare/23_proto_actor/remotebenchmark/node2/main.go (about) 1 package main 2 3 import ( 4 "log" 5 "runtime" 6 7 console "github.com/AsynkronIT/goconsole" 8 "github.com/AsynkronIT/protoactor-go/actor" 9 "github.com/AsynkronIT/protoactor-go/examples/remotebenchmark/messages" 10 "github.com/AsynkronIT/protoactor-go/mailbox" 11 "github.com/AsynkronIT/protoactor-go/remote" 12 ) 13 14 func main() { 15 runtime.GOMAXPROCS(runtime.NumCPU() * 1) 16 runtime.GC() 17 18 remote.Start("127.0.0.1:8080") 19 var sender *actor.PID 20 rootContext := actor.EmptyRootContext 21 props := actor. 22 PropsFromFunc( 23 func(context actor.Context) { 24 switch msg := context.Message().(type) { 25 case *messages.StartRemote: 26 log.Println("Starting") 27 sender = msg.Sender 28 context.Respond(&messages.Start{}) 29 case *messages.Ping: 30 context.Send(sender, &messages.Pong{}) 31 } 32 }). 33 WithMailbox(mailbox.Bounded(1000000)) 34 35 rootContext.SpawnNamed(props, "remote") 36 37 console.ReadLine() 38 }