-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (30 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
package main
import (
"fmt"
"log"
"os"
"github.com/verbruggenjesse/event-handler-mock-template/handler"
"github.com/verbruggenjesse/event-handler-mock-template/infrastructure"
"github.com/verbruggenjesse/event-handler-mock-template/mock"
"google.golang.org/grpc"
)
func main() {
var serverAddr string
if serverAddr = os.Getenv("EVENT_CENTRAL_ADDR"); serverAddr == "" {
log.Fatalln("Missing required environment variable 'EVENT_CENTRAL_ADDR'")
}
conn, err := grpc.Dial(serverAddr, grpc.WithInsecure())
if err != nil {
log.Fatal("Could not connect to central service")
}
defer conn.Close()
eventService := infrastructure.NewGrpcEventService(conn)
notificationService := &mock.NotificationService{}
echoHandler := handler.NewEchoMessageHandler(notificationService)
reverseHandler := handler.NewReverseMessageHandler(notificationService)
eventService.Subscribe("message", "echo", "", echoHandler)
eventService.Subscribe("message", "reverse", "", reverseHandler)
if err = eventService.ListenForEvents(); err != nil {
fmt.Println(err)
}
}