@hile/micro
Run registry-backed service discovery, RPC, streaming RPC, and pub/sub between Node services.Choose This Package When
Use When
Use the message packages for request/response messaging over WebSocket, process IPC, worker threads, file-system message handlers, service discovery, streaming RPC, and registry-backed pub/sub.Do Not Use When
- Do not use
stream()for normal single-result calls. - Do not rely on message IDs for business idempotency. They are transport IDs.
- Use
defineMicroMessage()for Micro business handlers; reserve genericdefineMessage()for transport-neutral loaders. - Do not pass zero, fractional, non-finite, or oversized message timeouts. Explicit timeout values must be safe integers from
1through2_147_483_647milliseconds.
Install
Imports
Copy-Paste Example
Message handler file:More Examples
Streaming handler:request() returns a Promise<T>. Await it directly.
Runtime And Lifecycle Notes
MessageLoadermaps*.msg.*files to routes using@hile/loader.MessageLoader.dispatch(path, data, extras?)invokes the matched handler.MessageModem._send()returns aPromise.MessageModem._send()and_push()use a30_000ms timeout when none is provided. An explicit timeout must be a safe integer from1through2_147_483_647; invalid values throwTypeErrorbefore a message is sent.MessageModem._stream()returns a NodeReadablein object mode.- Stream
timeoutandidleTimeoutvalues use the same1through2_147_483_647ms range. The streamwindowmust be a safe integer from1through64and defaults to1. - Each modem schedules request, total-stream, and idle-stream deadlines through one internal deadline scheduler. This reduces active Node.js timers without changing timeout, cancellation, ordering, or error semantics.
@hile/message-wskeeps publicdecodeMessageFrame()payloads isolated from caller-owned input by default. Its owned WebSocketRawDatapath uses a zero-copy binary Flight payload view internally.- A stream request requires
exec()to return an async iterable. Application.call(namespace, url, data, options)requiresoptions.contextand returns a promise.Application.stream(namespace, url, data, options)requiresoptions.contextand returns a readable stream.Application.publish(topic, payload)returns an object withupdate()andunpublish().Application.subscribe(topic, callback)returns an unsubscribe function.Registrystores service addresses and retained config/topic state under~/.registry.
Registry Read APIs
Registry exposes read-only routes for diagnostics and admin tooling. These routes return
snapshots of current registry state; they do not change service discovery, topic declarations,
subscriptions, or retained config data.
/-/namespacesreturns all registered namespaces with peer counts and addresses./-/namespace/peersaccepts{ namespace, exclude? }and returns every peer for one namespace./-/registry/statusreturns registry uptime and counts for clients, namespaces, topics, and config namespaces./-/topicsaccepts{ prefix? }and returns topic summaries with publisher/subscriber counts and retained/data flags./-/topic/getaccepts{ topic }and returns the current topic payload snapshot when the topic exists./-/configsreturns loaded config namespaces and keys./-/config/getaccepts{ namespace, key? }and returns either a config snapshot or one config value.
Anti-Patterns
- Appending a secondary response getter to
client.request('/x', data) - Returning a plain object from a handler called through
stream(). - Using pub/sub as a durable queue.
- Forgetting to register
shutdown(await app.listen(...)).
Verification Checklist
- Micro message files default-export
defineMicroMessage(...)and receiveinvocation.context. - RPC callers use
await app.call(..., { context }). - Streaming handlers are async generators.
- Custom modem timeout values use the documented safe-integer range.
- Registry is started before application nodes need discovery.
- Micro apps use stable namespaces and advertise reachable hosts.
Related Recipes
Micro RPC With Message Loader
Complete Example
Provider handler:Runtime Dynamic Config
Complete Example
Stable Runtime Reload
Complete Example
Package-Local AI Guide
This package also shipsAI.md in npm so agents can read accurate examples after installation.