Skip to main content

NATS Templates

Seven NATS patterns on wasmcloud:nats@0.1.0, each a self-contained project with source, a pinned WIT lockfile, and a manifest that runs on Cosmonic Control and Cosmonic Desktop alike. Each is available in Rust and Go.

Every manifest points at a prebuilt component published from the repository, so a pattern can be deployed and watched before any of it is built locally.

Repository: cosmonic-labs/awesome-cosmonic/components/nats Languages: Rust, Go Interfaces: wasmcloud:nats/{core,jetstream,kv}, wasmcloud:nats/{core,jetstream,kv}-handler

Which pattern do I want?​

TemplateShapeDelivery guaranteeUse when…
nats-core-subscriberHost subscribes, calls the component once per messagenone, fire and forgetTelemetry, cache invalidation, notifications. The cheapest consumer there is
nats-jetstream-consumerHost pushes stream messages, paced by acknowledgementat-least-once, with redeliveryDelivery has to be guaranteed, and you want backpressure rather than drops
nats-request-replyHost subscribes, the component publishes one reply to the request's inboxnone; the requester's timeout is the only boundA caller needs an answer over NATS: lookup, validation, RPC on subjects
nats-fan-outOne event in, a fixed set of downstream subjects outnone, and partial failure is not repairableOne event needs reshaping onto several subjects, routed in one place
nats-jetstream-workerGuest opens a pull consumer and fetches batches at its own paceat-least-once; you acknowledge each messageThe guest must control the rate: scheduled drains, a rate-limited downstream
nats-kv-storeMessages on a subject become keys in a JetStream KV bucketdurable write, revisionedDevice state, per-tenant settings, a last-known-value cache
nats-kv-watcherHost watches a bucket, calls the component per changereplayed; a redelivery can repeat oneReload config, invalidate a cache, mirror state onward

Start with nats-core-subscriber when losing a message is survivable, and nats-jetstream-consumer when it is not. Those two cover most workloads; the other five are for a specific need you can name.

Start from one​

Without cloning the repository:

wash new https://github.com/cosmonic-labs/awesome-cosmonic \
  --subfolder components/nats/rust/nats-core-subscriber

Swap rust for go to get the Go track. The Go templates build with componentize-go, which fetches the patched Go that WASI p3's async ABI requires; wasmcloud:nats@0.1.0 declares every function async func, and TinyGo cannot build these at all.

Grants come with the pattern​

Each template ships the grants its pattern needs and nothing more. They are deny-by-default ceilings, and the separation between them is easy to get wrong in both directions: see NATS Workloads and Grants. For sizing, see Tuning NATS Workloads.