github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/prepare/23_proto_actor/remoteactivate/node2/main.go (about)

     1  package main
     2  
     3  import (
     4  	"runtime"
     5  
     6  	console "github.com/AsynkronIT/goconsole"
     7  	"github.com/AsynkronIT/protoactor-go/actor"
     8  	"github.com/AsynkronIT/protoactor-go/examples/remoteactivate/messages"
     9  	"github.com/AsynkronIT/protoactor-go/remote"
    10  )
    11  
    12  type helloActor struct{}
    13  
    14  func (*helloActor) Receive(ctx actor.Context) {
    15  	switch ctx.Message().(type) {
    16  	case *messages.HelloRequest:
    17  		ctx.Respond(&messages.HelloResponse{
    18  			Message: "Hello from remote node",
    19  		})
    20  	}
    21  }
    22  
    23  func newHelloActor() actor.Actor {
    24  	return &helloActor{}
    25  }
    26  
    27  func init() {
    28  	remote.Register("hello", actor.PropsFromProducer(newHelloActor))
    29  }
    30  
    31  func main() {
    32  	runtime.GOMAXPROCS(runtime.NumCPU())
    33  
    34  	remote.Start("127.0.0.1:8080")
    35  
    36  	console.ReadLine()
    37  }