This repository has been archived by the owner on Jan 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
90 lines (78 loc) · 3.01 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"net"
"net/http"
"os"
"time"
"github.com/Financial-Times/content-collection-unfolder/differ"
fw "github.com/Financial-Times/content-collection-unfolder/forwarder"
prod "github.com/Financial-Times/content-collection-unfolder/producer"
"github.com/Financial-Times/content-collection-unfolder/relations"
res "github.com/Financial-Times/content-collection-unfolder/resolver"
logger "github.com/Financial-Times/go-logger"
"github.com/Financial-Times/message-queue-go-producer/producer"
"github.com/jawher/mow.cli"
)
const (
serviceName = "content-collection-unfolder"
serviceDescription = "UPP Service that forwards mapped content collections to the content-collection-rw-neo4j. If a 200 answer is received from the writer, it retrieves the elements in the collection from the document-store-api and places them in Kafka on the Post Publication topic so that notifications will be created for them."
)
func main() {
app := cli.App(serviceName, serviceDescription)
sc := createServiceConfiguration(app)
logger.InitDefaultLogger(serviceName)
app.Action = func() {
logger.Infof("[Startup] content-collection-unfolder is starting with service config %v", sc.toMap())
client := setupHttpClient()
producer := setupMessageProducer(sc, client)
unfolder := newUnfolder(
res.NewUuidResolver(),
relations.NewDefaultRelationsResolver(client, *sc.relationsResolverURI),
differ.NewDefaultCollectionsDiffer(),
fw.NewForwarder(client, *sc.writerURI),
res.NewContentResolver(client, *sc.contentResolverURI, time.Duration(*sc.requestTimeout)*time.Second),
prod.NewContentProducer(producer),
*sc.unfoldingWhitelist,
)
healthService := newHealthService(&healthConfig{
appDesc: serviceDescription,
port: *sc.appPort,
appSystemCode: *sc.appSystemCode,
appName: *sc.appName,
writerHealthURI: *sc.writerHealthURI,
contentResolverHealthURI: *sc.contentResolverHealthURI,
relationsResolverHealthURI: *sc.relationsResolverHealthURI,
producer: producer,
client: client,
})
routing := newRouting(unfolder, healthService)
routing.listenAndServe(*sc.appPort)
}
err := app.Run(os.Args)
if err != nil {
logger.Fatalf("App could not start, error=[%v]", err)
}
}
func setupHttpClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
MaxIdleConnsPerHost: 20,
TLSHandshakeTimeout: 3 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}
}
func setupMessageProducer(sc *serviceConfig, client *http.Client) producer.MessageProducer {
config := producer.MessageProducerConfig{
Addr: *sc.kafkaAddr,
Topic: *sc.writeTopic,
Queue: *sc.kafkaHostname,
Authorization: *sc.kafkaAuth,
}
return producer.NewMessageProducerWithHTTPClient(config, client)
}