forked from asynkron/protoactor-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (31 loc) · 773 Bytes
/
main.go
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
package main
import (
"fmt"
"runtime"
"github.com/AsynkronIT/goconsole"
"github.com/AsynkronIT/protoactor-go/actor"
"github.com/AsynkronIT/protoactor-go/examples/distributedchannels/messages"
"github.com/AsynkronIT/protoactor-go/remote"
)
func newMyMessageSenderChannel() chan<- *messages.MyMessage {
channel := make(chan *messages.MyMessage)
remote := actor.NewPID("127.0.0.1:8080", "MyMessage")
go func() {
for msg := range channel {
remote.Tell(msg)
}
}()
return channel
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
remote.Start("127.0.0.1:0")
channel := newMyMessageSenderChannel()
for i := 0; i < 10; i++ {
message := &messages.MyMessage{
Message: fmt.Sprintf("hello %v", i),
}
channel <- message
}
console.ReadLine()
}