-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwsqueue.go
More file actions
49 lines (45 loc) · 1.03 KB
/
wsqueue.go
File metadata and controls
49 lines (45 loc) · 1.03 KB
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
package main
import (
"encoding/base64"
"github.com/benmanns/goworker"
log "github.com/sirupsen/logrus"
)
func initQueueClient(webSocketsHub *WebSocketsHub) {
settings := goworker.WorkerSettings{
URI: "redis://" + Conf.Redis,
Connections: 10,
Queues: []string{Env.ServerID},
UseNumber: true,
ExitOnComplete: false,
Concurrency: 5,
Namespace: RKeyNS,
IntervalFloat: 0.2,
}
goworker.SetSettings(settings)
goworker.Register("Events", func(queue string, args ...interface{}) error {
switch sessionID := args[0].(type) {
case string:
switch messageB64 := args[1].(type) {
case string:
data, err := base64.StdEncoding.DecodeString(messageB64)
if err != nil {
log.Fatal(err)
return err
}
msg := &WebSocketOutMessage{
sessionID,
data,
}
webSocketsHub.outmessages <- msg
}
}
return nil
})
}
func startQueueProcessing() {
log.Info("Start queue processing")
if err := goworker.Work(); err != nil {
log.Fatal(err)
}
goworker.Close()
}