-
Notifications
You must be signed in to change notification settings - Fork 0
/
bridge_list.go
43 lines (38 loc) · 1.1 KB
/
bridge_list.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
package main
import (
"errors"
"fmt"
"log"
)
func bridgeList(control chan int, upstream side, b bridge) {
go func() {
defer signalFailure(control)
for {
if upstream.Connection.Client == nil {
log.Printf("no connection to %v", describeSide(upstream.Config))
break
}
// timeout=0 means infinite wait
entries := upstream.Connection.Client.BLPop(0, upstream.Config.Name)
result, err := entries.Result()
if err != nil {
log.Printf("failed to receive message from %v", describeSide(upstream.Config))
break
}
message := result[1]
log.Printf("message received from upstream %v: %v", describeSide(upstream.Config), message)
err = forward(message, b.Downstreams)
if err != nil {
log.Printf("failed to forward: %v", err)
break
}
}
}()
}
func forwardList(message string, downstream side) error {
if downstream.Connection.Client == nil {
return errors.New(fmt.Sprintf("no connection to %v", describeSide(downstream.Config)))
}
result := downstream.Connection.Client.RPush(downstream.Config.Name, message)
return handleResult(result, downstream, message)
}