Messaging
Copy-Paste Example
Message handler file:More Examples
Typed fixed-path operations
UsedefineMicroContract() and createMicroClient() from @hile/micro-contract to share stable JSON schemas and typed remote calls. Implement each operation in its matching message file with defineMicroMessage(operation, handler), then call loadMicroContract(app, contract, messagesDirectory) from @hile/micro to obtain { local, activate, close }.
The binding validates filesystem paths and complete implementation coverage before activation. Explicit local calls are same-service unary calls through the provider executor, not a namespace-based optimization; normal calls still use RPC. Typed remote calls default to zero retries. Native dynamic and streaming APIs remain supported. See Typed Micro contracts for the full example, schema constraints, and shutdown ordering.
Generic loader protocol registration
protocol on both sides. Protocol tags are nonempty printable ASCII strings, at most 128 characters; registration snapshots the value. Neither payload fields nor Context/extras can select the dispatch protocol.
After one route match, a different protocol throws MessageProtocolMismatchError (HILE_MESSAGE_PROTOCOL_MISMATCH) before the handler runs, with no fallback to another matching route. A tag prevents accidental protocol misdelivery, not unauthorized invocation by a caller able to set the tag.
Native streaming and custom transports
Streaming handler:AsyncIterable, Uint8Array, or
ArrayBuffer directly as data; Hile sends it as the request input stream and
the handler receives data === undefined. app.stream() accepts the same
request input forms when both request and response need to stream.
Custom WebSocket modem:
request() returns a Promise<T>. Await it directly.
Complete Example
Provider handler:operation.path values stay fixed and cannot use [id] or [...paths].
Provider boot:
Anti-Patterns
- Appending a secondary response getter to
client.request('/x', data) - Returning a plain object from a handler called through
stream(). - Retrying a consumed request stream or hiding it inside a replay-unsafe factory.
- Branching business code on whether a Micro target namespace is local or remote.
- Using pub/sub as a durable queue.
- Forgetting to register
shutdown(await app.listen(...)).