-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
77 lines (68 loc) · 1.88 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"log"
"os"
cli "github.com/jawher/mow.cli"
"github.com/xlab/closer"
peer "github.com/astranet/meshRPC-benchmark/peer/service"
"github.com/astranet/meshRPC/cluster"
)
var (
peerName = app.String(cli.StringOpt{
Name: "P peer-name",
Desc: "Specify peer name.",
EnvVar: "APP_PEER_NAME",
})
allPeers = app.Strings(cli.StringsOpt{
Name: "A all-peers",
Desc: "All peer names list.",
EnvVar: "APP_ALL_PEERS",
Value: []string{},
})
clusterNodes = app.Strings(cli.StringsOpt{
Name: "N nodes",
Desc: "A list of cluster nodes to join for service discovery.",
EnvVar: "MESHRPC_CLUSTER_NODES",
Value: []string{},
})
clusterName = app.String(cli.StringOpt{
Name: "T tag",
Desc: "Cluster tag name.",
EnvVar: "MESHRPC_CLUSTER_TAGNAME",
Value: "benchmark",
})
netAddr = app.String(cli.StringOpt{
Name: "listen-addr",
Desc: "Listen address for cluster discovery and private networking.",
EnvVar: "MESHRPC_LISTEN_ADDR",
Value: "0.0.0.0:0",
})
)
var app = cli.App("peer", "A Peer service server for meshRPC cluster, for benchmark purposes")
func main() {
app.Action = func() {
defer closer.Close()
c := cluster.NewAstraCluster(*peerName, &cluster.AstraOptions{
Tags: []string{
*clusterName,
},
Nodes: *clusterNodes,
Debug: true,
})
serviceMap := make(map[string]peer.Service, len(*allPeers))
for _, serviceName := range *allPeers {
peerClient := c.NewClient(serviceName, peer.RPCHandlerSpec)
serviceMap[serviceName] = peer.NewServiceClient(peerClient, nil)
log.Println("initialized RPC client for", serviceName)
}
service := peer.NewService(*peerName, serviceMap)
meshRPC := peer.NewRPCHandler(service, nil)
log.Println("service published as", *peerName)
c.Publish(meshRPC)
if err := c.ListenAndServe(*netAddr); err != nil {
log.Fatalln(err)
}
closer.Hold()
}
app.Run(os.Args)
}