An OpenFaaS event-connector to trigger functions from NATS Core pub/sub topics.
At most once QoS: Core NATS offers an at most once quality of service. If a subscriber is not listening on the subject (no subject match), or is not active when the message is sent, the message is not received. This is the same level of guarantee that TCP/IP provides. Core NATS is a fire-and-forget messaging system. It will only hold messages in memory and will never write messages directly to disk.
If no nats-connector is available at the time of a message being published, it will not be delivered to any functions. Likewise, if the function is unavailable or crashing, it will not receive the message. NATS Core has no durability.
For production and commercial use, see: JetStream for OpenFaaS
See the eBook Serverless For Everyone Else for instructions and sample YAML to add to your faasd host.
-
Deploy the connector using arkade
arkade install nats-connector
Alternatively, see the Helm chart
-
Deploy the two test functions
git clone https://github.com/openfaas/nats-connector --depth=1 cd nats-connector/contrib/test-functions
Deploy the functions using
stack.yml
, see how thereceive-message
function has thetopic=nats-test
annotation? That's how a function binds itself to a particular NATS Subject.faas-cli template pull stack faas-cli deploy
-
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"
Configuration of the binary is by environment variable. The names vary for the values.yaml file in the Helm chart.
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 |
, |