-
Notifications
You must be signed in to change notification settings - Fork 0
/
q.go
41 lines (37 loc) · 892 Bytes
/
q.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 main
import (
"context"
"log"
"fmt"
"net"
"github.com/sasidakh/kyu/q"
"github.com/sasidakh/kyu/q/store"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"google.golang.org/grpc"
)
func main() {
listner, err := net.Listen("tcp", fmt.Sprintf("localhost:%s", "50051"))
if err != nil {
log.Fatalln(err)
}
s := grpc.NewServer()
client, err := mongo.NewClient(
options.Client().ApplyURI(
"mongodb://localhost:27017,localhost:27018,localhost:27019/queue?replicaSet=mongodb-replicaset",
),
)
if err != nil {
log.Panicln(err)
}
if err := client.Connect(context.Background()); err != nil {
log.Panicln(err)
}
log.Println("Connected to database")
st := store.New(client, "queue", 1)
q.RegisterQServer(s, q.New(st))
log.Println("Queue at : ", listner.Addr())
if err := s.Serve(listner); err != nil {
log.Fatalln(err)
}
}