Categorygithub.com/openfaas/nats-connector
repositorypackage
0.0.0-20220831085931-183bc8b5580f
Repository: https://github.com/openfaas/nats-connector.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

nats-connector

build Go Report Card GoDoc License: MIT OpenFaaS

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.

From the NATS docs

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

Quick start

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

  1. Deploy the connector using arkade

    arkade install nats-connector
    

    Alternatively, see the Helm chart

  2. 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-message function has the topic=nats-test annotation? That's how a function binds itself to a particular NATS Subject.

    faas-cli template pull stack
    faas-cli deploy
    
  3. Now publish a message on the nats-test topic.

    Invoke the publisher

    faas-cli invoke publish-message <<< "test message"
    
  4. 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

Configuration of the binary is by environment variable. The names vary for the values.yaml file in the Helm chart.

VariableDescriptionDefault
topicsDelimited list of topicsnats-test,
broker_hostThe host, but not the port for NATSnats
async_invocationQueue the invocation with the built-in OpenFaaS queue-worker and return immediatelyfalse
gateway_urlThe URL for the OpenFaaS gatewayhttp://gateway:8080
upstream_timeoutTimeout to wait for synchronous invocations60s
rebuild_intervalInterval at which to rebuild the map of topics <> functions5s
topic_delimiterUsed to separate items in topics variable,