-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (39 loc) · 951 Bytes
/
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
package main
import (
"fmt"
"log"
"github.com/Vractos/go-reports-service/infra/kafka"
"github.com/Vractos/go-reports-service/infra/repository"
"github.com/Vractos/go-reports-service/usacase"
ckafka "github.com/confluentinc/confluent-kafka-go/kafka"
"github.com/elastic/go-elasticsearch/v8"
"github.com/joho/godotenv"
)
func init() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
}
func main() {
client, err := elasticsearch.NewClient(elasticsearch.Config{
Addresses: []string{
"http://host.docker.internal:9200",
},
})
if err != nil {
log.Fatal("Error connecting to elasticsearch")
}
repo := repository.TransactionElasticRepository{
Client: *client,
}
msgChan := make(chan *ckafka.Message)
consumer := kafka.NewKafkaConsumer(msgChan)
go consumer.Consume()
for msg := range msgChan {
err := usacase.GenetareReport(msg.Value, repo)
if err != nil {
fmt.Println(err)
}
}
}