NATS KV Store

Read, write, list, and delete keys in a NATS JetStream Key-Value bucket.

Operations

OperationDescription
getRead a value by key.
putWrite a value. Uses event.data.content if present, otherwise the full event data.
listList keys matching a prefix.
deleteDelete a key.

Configuration

- nats_kv_store:
    name: write_flow
    operation: put
    credentials_path: /etc/nats/credentials.json
    url: nats://localhost:4222
    bucket: flowgen_system
    key: "flows.{{event.data.path}}"

Fields

FieldTypeDefaultDescription
namestringrequiredTask name.
operationstringrequiredOne of get, put, list, delete.
credentials_pathstringrequiredPath to NATS credentials file.
urlstringlocalhost:4222NATS server URL.
bucketstringrequiredKV bucket name.
keystringKey for get, put, and delete. Supports templating.
key_prefixstringKey prefix for list operations. Supports templating.
depends_onlistUpstream task names.
retryobjectRetry configuration.

Output

Format: JSON

get

FieldTypeDescription
keystringRequested key.
contentstring / nullStored value, or null if not found.
foundboolWhether the key exists.

put

FieldTypeDescription
keystringWritten key.
revisionintKV store revision number.

delete

FieldTypeDescription
keystringDeleted key.

list

FieldTypeDescription
keysarrayMatching key names.
countintNumber of keys returned.
prefixstringPrefix that was searched.

Examples

Write to KV

- nats_kv_store:
    name: save_config
    operation: put
    bucket: flowgen_system
    key: "config.{{event.data.name}}"
    credentials_path: /etc/nats/credentials.json

Read from KV

- nats_kv_store:
    name: load_config
    operation: get
    bucket: flowgen_system
    key: "config.my_setting"
    credentials_path: /etc/nats/credentials.json

Returns {key, content, found}. content is null if the key does not exist.

List keys

- nats_kv_store:
    name: list_flows
    operation: list
    bucket: flowgen_system
    key_prefix: "flows."
    credentials_path: /etc/nats/credentials.json

Returns {prefix, keys, count}.

Delete a key

- nats_kv_store:
    name: remove_config
    operation: delete
    bucket: flowgen_system
    key: "config.old_setting"
    credentials_path: /etc/nats/credentials.json