---
name: "nats-jetstream-at-least-once"
description: "Implement lightweight, high-speed publish-subscribe and persistent streams with NATS JetStream."
metadata:
  author: "NATS"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "create nats jetstream stream"
  - "consume nats jetstream messages"
  - "setup nats kv bucket"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# NATS JetStream Persistence & Distributed Messaging

Builds messaging architectures with NATS JetStream: creating file/memory streams, defining consumer subjects, configuring at-least-once / exactly-once acknowledgments, key-value (KV) buckets, and object stores.

## When to Invoke
Invoke this skill whenever you need to:
- create nats jetstream stream
- consume nats jetstream messages
- setup nats kv bucket

## Execution SOP & Rules
1. Enable JetStream in nats-server configuration: jetstream: { store_dir: '/data/jetstream' }.
2. Create stream: js.AddStream(&nats.StreamConfig{ Name: 'ORDERS', Subjects: []string{'orders.*'} }).
3. Create pull consumer and fetch batches: msgs, _ := sub.Fetch(10, nats.MaxWait(time.Second)).
4. Acknowledge message processing: msg.Ack() or call msg.NakWithDelay() on transient failures.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
