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?
| Template | Shape | Delivery guarantee | Use when… |
|---|---|---|---|
| nats-core-subscriber | Host subscribes, calls the component once per message | none, fire and forget | Telemetry, cache invalidation, notifications. The cheapest consumer there is |
| nats-jetstream-consumer | Host pushes stream messages, paced by acknowledgement | at-least-once, with redelivery | Delivery has to be guaranteed, and you want backpressure rather than drops |
| nats-request-reply | Host subscribes, the component publishes one reply to the request's inbox | none; the requester's timeout is the only bound | A caller needs an answer over NATS: lookup, validation, RPC on subjects |
| nats-fan-out | One event in, a fixed set of downstream subjects out | none, and partial failure is not repairable | One event needs reshaping onto several subjects, routed in one place |
| nats-jetstream-worker | Guest opens a pull consumer and fetches batches at its own pace | at-least-once; you acknowledge each message | The guest must control the rate: scheduled drains, a rate-limited downstream |
| nats-kv-store | Messages on a subject become keys in a JetStream KV bucket | durable write, revisioned | Device state, per-tenant settings, a last-known-value cache |
| nats-kv-watcher | Host watches a bucket, calls the component per change | replayed; a redelivery can repeat one | Reload 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-subscriberSwap 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.