forked from kyma-project/kyma
/
application.go
52 lines (43 loc) · 1.55 KB
/
application.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
package application
import (
"log"
"net/http"
"github.com/kyma-project/kyma/components/event-bus/cmd/event-bus-publish/controllers"
"github.com/kyma-project/kyma/components/event-bus/cmd/event-bus-publish/handlers"
"github.com/kyma-project/kyma/components/event-bus/internal/publish"
"github.com/kyma-project/kyma/components/event-bus/internal/trace"
)
type PublishApplication struct {
publisher controllers.Publisher
tracer trace.Tracer
ServerMux *http.ServeMux
}
func NewPublishApplication(publishOpts *publish.Options) *PublishApplication {
log.Println("Publish :: Initializing NATS Streaming publisher")
publisher := controllers.GetPublisher(publishOpts.ClientID, publishOpts.NatsURL, publishOpts.NatsStreamingClusterID)
err := publisher.Start()
if err != nil {
log.Fatalf("Error while initializing NATS Streaming publisher. %v", err)
}
log.Println("Publish :: Initializing tracer")
traceOpts := trace.Options{
APIURL: publishOpts.TraceAPIURL,
HostPort: publishOpts.TraceHostPort,
ServiceName: publishOpts.ServiceName,
OperationName: publishOpts.OperationName,
Debug: publishOpts.TraceDebug,
}
tracer := trace.StartNewTracer(&traceOpts)
serveMux := http.NewServeMux()
serveMux.HandleFunc("/v1/events", handlers.GetPublishHandler(&publisher, &tracer))
serveMux.HandleFunc("/v1/status/ready", handlers.GetReadinessHandler(&publisher))
return &PublishApplication{
publisher: publisher,
tracer: tracer,
ServerMux: serveMux,
}
}
func (app *PublishApplication) Stop() {
app.publisher.Stop()
app.tracer.Stop()
}