-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (34 loc) · 928 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
39
40
41
42
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/charlesderek/actor-model/actor"
"github.com/charlesderek/actor-model/examples/mdns/chat"
"github.com/charlesderek/actor-model/examples/mdns/discovery"
"github.com/charlesderek/actor-model/remote"
)
var (
port = flag.Int("port", 4001, "Set the port the service is listening to.")
ip = flag.String("ip", "127.0.0.1", "Set IP a service should be reachable.")
)
func main() {
flag.Parse()
engine := actor.NewEngine()
r := remote.New(engine, remote.Config{
ListenAddr: fmt.Sprintf("%s:%d", *ip, *port),
})
engine.WithRemote(r)
engine.Spawn(chat.New(engine.EventStream), "chat")
// starts mdns discovery
engine.Spawn(discovery.NewMdnsDiscovery(
engine.EventStream,
discovery.WithAnnounceAddr(*ip, *port),
), "mdns")
// Clean exit.
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
<-sig
}