-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (40 loc) · 1.08 KB
/
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 (
"encoding/json"
"fmt"
zmq "github.com/alecthomas/gozmq"
"github.com/altonymous/api.6fusion.com/models"
riak "github.com/tpjg/goriakpbc"
)
func main() {
context, _ := zmq.NewContext()
socket, _ := context.NewSocket(zmq.REP)
socket.Bind("tcp://127.0.0.1:5000")
socket.Bind("tcp://127.0.0.1:6000")
for {
msg, _ := socket.Recv(0)
var machine models.Machine
err := json.Unmarshal(msg, &machine)
machineJson, err := json.Marshal(machine)
if err != nil {
fmt.Println("error:", err)
}
// println("Got", string(msg))
storeData(machine.UUID, machineJson)
socket.Send(msg, 0)
}
}
func storeData(machineUUID string, machineJson []byte) {
err := riak.ConnectClient("127.0.0.1:8087")
if err != nil {
fmt.Println("Cannot connect, is Riak running?")
return
}
bucket, _ := riak.NewBucket("6fusion")
obj := bucket.NewObject(machineUUID)
obj.ContentType = "application/json"
obj.Data = []byte(machineJson)
obj.Store()
fmt.Printf("Stored an object in Riak, vclock = %v\n", obj.Vclock)
riak.Close()
}