Skip to main content

@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.
  • Do not bypass defineMessage() for file-loaded handlers.

Install

Use transport-specific packages only when you need to build custom IPC or worker-thread bridges.

Imports

Copy-Paste Example

Message handler file:
Microservice boot file:
Caller:

More Examples

Streaming handler:
Streaming caller:
Custom WebSocket modem:
Notice that request() returns a Promise<T>. Await it directly.

Runtime And Lifecycle Notes

  • MessageLoader maps *.msg.* files to routes using @hile/loader.
  • MessageLoader.dispatch(path, data, extras?) invokes the matched handler.
  • MessageModem._send() returns a Promise.
  • MessageModem._stream() returns a Node Readable in object mode.
  • A stream request requires exec() to return an async iterable.
  • Application.call(namespace, url, data, options?) returns a promise.
  • Application.stream(namespace, url, data, options?) returns a readable stream.
  • Application.publish(topic, payload) returns an object with update() and unpublish().
  • Application.subscribe(topic, callback) returns an unsubscribe function.
  • Registry stores 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.
  • /-/namespaces returns all registered namespaces with peer counts and addresses.
  • /-/namespace/peers accepts { namespace, exclude? } and returns every peer for one namespace.
  • /-/registry/status returns registry uptime and counts for clients, namespaces, topics, and config namespaces.
  • /-/topics accepts { prefix? } and returns topic summaries with publisher/subscriber counts and retained/data flags.
  • /-/topic/get accepts { topic } and returns the current topic payload snapshot when the topic exists.
  • /-/configs returns loaded config namespaces and keys.
  • /-/config/get accepts { 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

  • Message files default-export defineMessage(...).
  • RPC callers use await app.call(...).
  • Streaming handlers are async generators.
  • Registry is started before application nodes need discovery.
  • Micro apps use stable namespaces and advertise reachable hosts.

Micro RPC With Message Loader

Complete Example

Provider handler:
Provider boot:
Consumer:

Runtime Dynamic Config

Complete Example

Stable Runtime Reload

Complete Example

Package-Local AI Guide

This package also ships AI.md in npm so agents can read accurate examples after installation.