-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
45 lines (36 loc) · 887 Bytes
/
cli.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
package cli
import (
"flag"
"log"
"time"
"github.com/a1fred/nats-resender/src/options"
"github.com/a1fred/nats-resender/src/resender"
)
func Main() {
options := options.NewOptions()
var err error
flag.Parse()
nn := resender.NewResender(options.FromNats, options.ToNats)
defer nn.Close()
_, err = nn.Subscribe(
options.FromNats.Subject,
options.Queue,
options.ToNats.Subject,
options.PendingMsgLimit, options.PendingByteLimit, options.Debug)
if err != nil {
log.Fatalln(err)
}
for {
start := time.Now()
time.Sleep(time.Duration(options.StatPrintPeriod) * time.Second)
elapsed := time.Since(start).Seconds()
processedCounter, q_msgs, q_bytes := nn.FlushCounter()
log.Printf(
"%d processed, %.2fs elapsed, %.2f msg/sec, buffer:%dmsgs/%dbytes",
processedCounter,
elapsed,
float64(processedCounter)/elapsed,
q_msgs, q_bytes,
)
}
}