An OpenFaaS event-connector to trigger functions from NATS Core pub/sub topics.
Is the nats-connector or JetStream for OpenFaaS right for you?
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
Deploy the connector to faasd
See the eBook Serverless For Everyone Else for instructions and sample YAML to add to your faasd host.
Or deploy the connector to Kubernetes
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 the
receive-messagefunction has the
topic=nats-testannotation? 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
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.
||Delimited list of topics||
||The host, but not the port for NATS||
||Queue the invocation with the built-in OpenFaaS queue-worker and return immediately||
||The URL for the OpenFaaS gateway||
||Timeout to wait for synchronous invocations||
||Interval at which to rebuild the map of topics <> functions||
||Used to separate items in