Support customising the NATS Streaming channel.

Signed-off-by: Bruno Miguel Custódio <brunomcustodio@gmail.com>
This commit is contained in:
Bruno Miguel Custódio
2019-12-10 11:06:47 +00:00
committed by Alex Ellis
parent 3422bdcce9
commit 03dc8824d2
7 changed files with 39 additions and 7 deletions

View File

@ -106,6 +106,14 @@ func (ReadConfig) Read(hasEnv HasEnv) (*GatewayConfig, error) {
cfg.NATSClusterName = &v
}
faasNATSChannel := hasEnv.Getenv("faas_nats_channel")
if len(faasNATSChannel) > 0 {
cfg.NATSChannel = &faasNATSChannel
} else {
v := "faas-request"
cfg.NATSChannel = &v
}
prometheusPort := hasEnv.Getenv("faas_prometheus_port")
if len(prometheusPort) > 0 {
prometheusPortVal, err := strconv.Atoi(prometheusPort)
@ -197,6 +205,9 @@ type GatewayConfig struct {
// The name of the NATS Streaming cluster. Required for async mode.
NATSClusterName *string
// NATSChannel is the name of the NATS Streaming channel used for asynchronous function invocations.
NATSChannel *string
// Host to connect to Prometheus.
PrometheusHost string

View File

@ -255,6 +255,12 @@ func TestRead_UseNATS(t *testing.T) {
t.Fail()
}
wantNATSChannel := "faas-request"
if *config.NATSChannel != wantNATSChannel {
t.Logf("faas_nats_channel: want %s, got %s", wantNATSChannel, *config.NATSChannel)
t.Fail()
}
defaults.Setenv("faas_nats_cluster_name", "example-nats-cluster")
config, _ = readConfig.Read(defaults)
@ -263,6 +269,15 @@ func TestRead_UseNATS(t *testing.T) {
t.Logf("faas_nats_cluster_name: want %s, got %s", wantNATSClusterName, *config.NATSClusterName)
t.Fail()
}
defaults.Setenv("faas_nats_channel", "foo")
config, _ = readConfig.Read(defaults)
wantNATSChannel = "foo"
if *config.NATSChannel != wantNATSChannel {
t.Logf("faas_nats_channel: want %s, got %s", wantNATSChannel, *config.NATSChannel)
t.Fail()
}
}
func TestRead_UseNATSBadPort(t *testing.T) {