forked from oklahomer/protoactor-go-sender-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (47 loc) · 1.41 KB
/
main.go
File metadata and controls
57 lines (47 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"github.com/asynkron/protoactor-go/actor"
"github.com/asynkron/protoactor-go/cluster"
"github.com/asynkron/protoactor-go/cluster/clusterproviders/automanaged"
"github.com/asynkron/protoactor-go/cluster/identitylookup/disthash"
"github.com/asynkron/protoactor-go/remote"
"log"
"os"
"os/signal"
"protoactor-go-sender-example/cluster/messages"
"time"
)
type ponger struct {
}
func (*ponger) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
case *messages.PingMessage:
pong := &messages.PongMessage{Cnt: msg.Cnt}
log.Print("Received ping message")
ctx.Respond(pong)
default:
}
}
func main() {
// Set up the actor system
system := actor.NewActorSystem()
// Prepare a remote env that listens to 8080
config := remote.Configure("127.0.0.1", 8080)
// Configure a cluster on top of the above remote env
provider := automanaged.NewWithConfig(1*time.Second, 6331, "localhost:6331")
lookup := disthash.New()
clusterKind := cluster.NewKind(
"Ponger",
actor.PropsFromProducer(func() actor.Actor {
return &ponger{}
}))
clusterConfig := cluster.Configure("cluster-example", provider, lookup, config, cluster.WithKinds(clusterKind))
c := cluster.New(system, clusterConfig)
// Manage the cluster node's lifecycle
c.StartMember()
defer c.Shutdown(false)
// Run till a signal comes
finish := make(chan os.Signal, 1)
signal.Notify(finish, os.Interrupt, os.Kill)
<-finish
}