An OpenFaaS event-connector to trigger functions from NATS.
Test functions have been created to help you verify the installation of nats-connector
. See contrib/test-functions
.
The following instructions show how to run and test nats-connector
on Kubernetes.
-
Deploy the receiver functions, the receiver function must have the
topic
annotation:export OPENFAAS_URL="http://localhost:8080" # Set your gateway via env variable or the -g flag faas-cli deploy --name receive-message --image openfaas/receive-message:latest --fprocess='./handler' --annotation topic="nats-test"
Or deploy with the
stack.yml
provided in this repo:cd contrib/test-functions faas-cli template pull stack faas-cli deploy --filter receive-message
-
Deploy the connector with:
kubectl apply -f ./yaml/kubernetes/connector-dep.yaml
-
Deploy the
publish-message
functionfaas-cli deploy --name publish-message --image openfaas/publish-message:latest --fprocess='./handler' --env nats_url=nats://nats.openfaas:4222
Or deploy via
stack.yml
cd contrib/test-functions faas-cli template pull stack faas-cli deploy --filter publish-message
-
Now publish a message on the
nats-test
topic.Invoke the publisher
faas-cli invoke publish-message <<< "test message"
-
Verify that the receiver was invoked by checking the logs
faas-cli logs receive-message 2019-12-29T19:06:50Z 2019/12/29 19:06:50 received "test message"
Build and release is done via CI, but you can also build your own version locally.
export TAG=0.2.1
make build push
Configuration is by environment variable, which can be set in the Kubernetes YAML file: yaml/kubernetes/connector-dep.yaml
Variable | Description | Default |
---|---|---|
topics |
Delimited list of topics | nats-test, |
broker_host |
The host, but not the port for NATS | nats |
async-invocation |
Queue the invocation with the built-in OpenFaaS queue-worker and return immediately | false |
gateway_url |
The URL for the OpenFaaS gateway | http://gateway:8080 |
upstream_timeout |
Timeout to wait for synchronous invocations | 60s |
rebuild_interval |
Interval at which to rebuild the map of topics <> functions | 5s |
topic_delimiter |
Used to separate items in topics variable |
, |