-
Notifications
You must be signed in to change notification settings - Fork 0
/
counterApp.go
77 lines (62 loc) · 1.53 KB
/
counterApp.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"context"
pb "counterGrpc"
"google.golang.org/grpc"
"log"
"net"
)
const (
port = ":50051"
)
var counter int32
/*type CounterQueueImpl struct {
}
func NewCounterQueueImpl() *CounterQueueImpl{
return &CounterQueueImpl{}
}*/
type server struct {
pb.UnimplementedCounterQueueServer
}
func (s *server) RequestCounter(ctx context.Context, in *pb.CounterGrpc) (*pb.CounterGrpc, error){
log.Printf("Server counterApp recieved: token: %v, count: %v", in.GetToken(), in.GetCount())
counter = counter + 1
return &pb.CounterGrpc{Token: in.GetToken(), Count: counter}, nil
}
func main(){
counter = 0
lis, err := net.Listen("tcp", port)
if err != nil{
log.Fatalf("fail to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterCounterQueueServer(s, &server{})
if err:= s.Serve(lis); err != nil{
log.Fatalf("fail to serve: %v", err)
}
}
/*func counterApp(){
counter := 0
//counterCh := make(chan counterRabbitMQ)
for {
////Counter stay local in counterApp now so this
//dequeue grpc
rabbitMQRecieve(*ch, sendQname, counterCh)
countMQ := <-counterCh
log.Printf("in app, recieve token and counter %v", countMQ)
counter = counter + 1
countMQ.Count = counter
//send respond to grpc
err = ch.Publish(
"", // exchange
receiveQname, // routing key
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "text/plain",
Body: json,
})
failOnError(err, "Failed to publish a message")
log.Printf("in app, send %v to rabbitMQ", countMQ)
}
}*/