-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
70 lines (58 loc) · 1.91 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
// Copyright (c) OpenFaaS Author(s) 2020. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import (
"fmt"
"log"
"strconv"
"github.com/openfaas/connector-sdk/types"
"github.com/openfaas/nats-connector/config"
"github.com/openfaas/nats-connector/nats"
"github.com/openfaas/nats-connector/version"
)
func main() {
creds := types.GetCredentials()
config := config.Get()
controllerConfig := &types.ControllerConfig{
UpstreamTimeout: config.UpstreamTimeout,
GatewayURL: config.GatewayURL,
RebuildInterval: config.RebuildInterval,
PrintResponse: config.PrintResponse,
PrintResponseBody: config.PrintResponseBody,
TopicAnnotationDelimiter: config.TopicAnnotationDelimiter,
AsyncFunctionInvocation: config.AsyncFunctionInvocation,
PrintSync: config.PrintSync,
}
controller := types.NewController(creds, controllerConfig)
controller.BeginMapBuilder()
brokerConfig := nats.BrokerConfig{
Host: config.Broker,
ConnTimeout: config.UpstreamTimeout, // ConnTimeout isn't the same as UpstreamTimeout, it's just the delay to connect to NATS.
}
sha, ver := version.GetReleaseInfo()
fmt.Printf(`==============================================================================
NATS Connector for OpenFaaS %s (%s)
Gateway URL: %s
NATS URL: nats://%s:4222
Topics: %s
Upstream timeout: %s
Topic-map rebuild interval: %s
Async invocation: %q
==============================================================================
`, sha,
ver,
config.GatewayURL,
config.Broker,
config.Topics,
config.UpstreamTimeout,
config.RebuildInterval,
strconv.FormatBool(config.AsyncFunctionInvocation),
)
broker, err := nats.NewBroker(brokerConfig)
if err != nil {
log.Fatal(err)
}
if err = broker.Subscribe(controller, config.Topics); err != nil {
log.Fatal(err)
}
}