-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
52 lines (44 loc) · 996 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
43
44
45
46
47
48
49
50
51
52
package main
import (
"context"
"flag"
"log"
"os"
"os/signal"
"syscall"
"github.com/alifpay/qs/app"
)
func main() {
//nats server urls
addr := os.Getenv("natsurl")
if addr == "" {
addr = *flag.String("natsurl", "nats://127.0.0.1:4222", "nats url")
}
//nats token
token := os.Getenv("natstoken")
if token == "" {
token = *flag.String("natstoken", "123wexsx2asekcijyc", "nats token")
}
//queue service subject name
subj := os.Getenv("subject")
if subj == "" {
subj = *flag.String("subject", "EnQueue", "qs subject name")
}
//queue service stream name
str := os.Getenv("stream")
if str == "" {
str = *flag.String("stream", "qsStream21", "qs subject name")
}
ctx, cancel := context.WithCancel(context.Background())
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
go func() {
<-sig
signal.Stop(sig)
close(sig)
cancel()
}()
log.Println("Queue Service is running")
j := app.New(addr, token, subj, str)
j.Run(ctx)
}