-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgo0mq.go
41 lines (34 loc) · 905 Bytes
/
go0mq.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
package goshare
import (
"fmt"
"runtime"
"strings"
zmq "github.com/alecthomas/gozmq"
golzmq "github.com/abhishekkr/gol/golzmq"
)
/*
goShareZmqRep handles Read/Push/Delete tasks diversion based on task-type.
*/
func goShareZmqRep(socket *zmq.Socket) {
var errResponse string
for {
msg, _ := socket.Recv(0)
messageArray := strings.Fields(string(msg))
responseBytes, axnStatus := DBTasks(messageArray)
if axnStatus {
socket.Send([]byte(responseBytes), 0)
} else {
errResponse = fmt.Sprintf("Error for request sent: %s", msg)
socket.Send([]byte(errResponse), 0)
}
}
}
/*
GoShareZMQ starts a Daemon communicating of provided array ports over ZMQ Reply.
*/
func GoShareZMQ(ip string, replyPorts []int) {
fmt.Printf("starting ZeroMQ REP/REQ at %v\n", replyPorts)
runtime.GOMAXPROCS(runtime.NumCPU())
socket := golzmq.ZmqReplySocket(ip, replyPorts)
goShareZmqRep(socket)
}