-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (73 loc) · 1.65 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
78
79
80
81
82
83
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
"time"
"flag"
"github.com/oldtree/Axon/axonx"
"github.com/oldtree/Axon/monitor"
"github.com/oldtree/Axon/axonx/config"
"github.com/oldtree/Axon/axonx/ins"
)
var instance = &ins.JsonProtocol{}
func Server() {
s := axonx.NewAxonSrv(instance)
s.Address = "127.0.0.1:8090"
err := s.Start()
if err != nil {
fmt.Printf("error : %s", err.Error())
}
select {}
}
func Client() {
var ext = make(chan struct{}, 1)
cell, err := axonx.NewCellClientUseAddress(config.GetCfg().SrvAddress, instance, ext)
if err != nil {
fmt.Println(err.Error())
return
}
go cell.Active()
time.Sleep(time.Second * 1)
for index := 0; index < 10000000; index++ {
time.Sleep(time.Second * 50)
_, err := cell.Write([]byte(`{"msg":"golang"}`))
if err != nil {
break
}
//fmt.Printf("cell %s msg length : %d error : %v time %s \n", cell.LocalAddr().String(), n, err, time.Now().String())
}
}
func JsonServer() {
go Server()
time.Sleep(time.Second * 5)
for index := 0; index < 400; index++ {
go Client()
if index%50 == 0 {
time.Sleep(time.Second * 5)
}
}
}
var conf = flag.String("c", "cfg.json", "config file")
func main() {
flag.Parse()
err := config.LoadCfg(*conf)
if err != nil {
os.Exit(-1)
}
runtime.GOMAXPROCS(runtime.NumCPU())
go axonx.DebugServer(config.GetCfg().DebugAddress)
m := monitor.NewMonitor(config.GetCfg().Influx.Address, config.GetCfg().Influx.Username,
config.GetCfg().Influx.Password, config.GetCfg().Influx.Databasename)
go m.Dog()
go JsonServer()
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT,
)
<-sc
}