{"metadata":{"name":"hew/queue/nats","vers":"0.7.3","description":"Typed, actor-owned NATS pub/sub and request/reply client","license":"MIT OR Apache-2.0","authors":["Hew Contributors"],"deps":[],"features":{},"keywords":["messaging","nats","pubsub","queue"],"repository":"https://github.com/hew-lang/ecosystem","edition":"2026","hew":">=0.10.0, <0.12.0","readme":"# hew.queue.nats\n\nA typed, actor-owned NATS client for publish/subscribe and request/reply.\nSubscriptions are owned by their connection actor, receive timeouts are\n`Receive.Missing`, and messages are immutable `#[wire]` snapshots.\n\nRun a server and the example from the repository root:\n\n```sh\ndocker run --rm -d --name hew-nats -p 14222:4222 nats:2.11.8-alpine3.22\nhew run --pkg-path . queue/nats/examples/pubsub.hew\n```\n\nEach `Conn` method is a `receive fn` that returns `T fails NatsError`, so a\ncall replies with `Result<T, ActorError<NatsError>>`: `.Ok(value)` on success,\n`.Err(.Failed(error))` when the NATS operation fails, and another `.Err` when\nthe actor could not answer.\n\n```hew\nimport hew.queue.nats;\n\nfn main() {\n    let client = spawn nats.Conn { options: nats.Options { url: \"nats://127.0.0.1:14222\" } };\n    match client.subscribe(\"hew.readme\") {\n        .Ok(subscription) => {\n            let _ = client.publish(\"hew.readme\", \"hello\");\n            match client.next_message(subscription.clone(), 1000) {\n                .Ok(.Message(message)) => println(message.data),\n                .Ok(.Missing) => println(\"no message arrived\"),\n                .Err(.Failed(error)) => println(nats.error_message(error)),\n                .Err(_) => println(\"NATS actor stopped before replying\"),\n            }\n            let _ = client.unsubscribe(subscription);\n        }\n        .Err(.Failed(error)) => println(nats.error_message(error)),\n        .Err(_) => println(\"NATS actor stopped before replying\"),\n    }\n    stop(client);\n    stopped(client);\n}\n```\n\n## API surface\n\n- `actor Conn` — owns one NATS connection and every subscription it creates.\n  - `init(options: Options)`\n  - `receive fn publish(subject: string, data: string) fails NatsError`\n  - `receive fn subscribe(subject: string) -> Subscription fails NatsError`\n  - `receive fn next_message(subscription: Subscription, timeout_ms: i64) -> Receive fails NatsError`\n  - `receive fn request(subject: string, data: string, timeout_ms: i64) -> Receive fails NatsError`\n  - `receive fn reply(message: Delivery, data: string) fails NatsError`\n  - `receive fn unsubscribe(subscription: Subscription)`\n- `stop(client); stopped(client);` — gracefully stop the actor and wait for connection cleanup.\n- `type Options { url: string; }`\n- `type Subscription { handle: i64; }`\n- `type Delivery { subject: string; data: string; reply_to: ReplyTo; }`\n- `enum ReplyTo { Missing; Subject(string); }`\n- `enum Receive { Missing; Message(Delivery); }`\n- `enum NatsError { Connection; InvalidInput; Operation; Closed; Internal; }` — each variant carries a diagnostic `string`.\n- `fn error_message(error: NatsError) -> string` — extracts the diagnostic from any `NatsError` variant.\n"},"version":{"name":"hew/queue/nats","vers":"0.6.0","deps":[],"features":{},"cksum":"sha256:f9144ab00d328c58b300d939a5bafaf8229ea32efd1c8322310cc0a9a2c5c6fa","sig":"ed25519:e6034d4bbe4238901ef171e143f75655891b743792a9b026c8ab4590bd5e859e63310349156c01acae279a8420c549a6cc9285ab6998a94316eb0ee291057100","key_fp":"SHA256:CB3Ski8183EXzxoy+uSuMpWTxvd/4AlB8CThZu0ZG74","yanked":false,"edition":"2026","hew":">=0.9.0, <0.10.0","registry_sig":"ed25519:c61fd2007eac7c92f091f5c704b064e910ab76378707fadbb678c9dfdcdf6213bb934abfda3812b796f9b2e70c78050e4bd026f0e3dafb7b6ecb86789fb85509","registry_key_fp":"SHA256:NR2yrof9/ZWkCWyhDODRU8Yvm9Lob/0yYVTdCKzMHb8","published_at":"2026-10-24T11:54:15.325Z","dl":"https://cdn.hewpkg.com/tarballs/hew/queue/nats/0.6.0.tar.zst"}}