@btravstack/amqp
@btravstack/amqp
Classes
AmqpConfig
Defined in: amqp/src/amqp-runtime.ts:31
The broker, as a service: amqp() binds it from AMQP_URL (default amqp://127.0.0.1:5672) unless pinned, and anything else in the graph may read it — a publisher sharing the consumer's broker, say.
Extends
PortInstance<"AmqpConfig", {url:string; }>
Constructors
Constructor
new AmqpConfig(): AmqpConfig;Defined in: di/dist/index.d.mts:15
Returns
Inherited from
Port("AmqpConfig")<{ readonly url: string }>.constructorProperties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
[ID] | readonly | "AmqpConfig" | Port("AmqpConfig").[ID] | di/dist/index.d.mts:11 |
[SERVICE] | readonly | object | Port("AmqpConfig").[SERVICE] | di/dist/index.d.mts:12 |
[SERVICE].url | readonly | string | - | amqp/src/amqp-runtime.ts:31 |
portId | readonly | "AmqpConfig" | Port("AmqpConfig").portId | di/dist/index.d.mts:16 |
AmqpRuntime
Defined in: amqp/src/amqp-runtime.ts:34
The runtime's port: what amqp() provides, and what the module start boots must export.
Extends
RuntimePort<Runtime<never,AmqpInfo>>
Constructors
Constructor
new AmqpRuntime(): AmqpRuntime;Defined in: di/dist/index.d.mts:15
Returns
Inherited from
RuntimePort<Runtime<never, AmqpInfo>>.constructorProperties
Type Aliases
AmqpInfo
type AmqpInfo = object;Defined in: amqp/src/amqp-runtime.ts:24
What the worker publishes once it is consuming, read back through RunningApp.runtimeInfo().
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
queues | readonly | readonly string[] | amqp/src/amqp-runtime.ts:24 |
AmqpModuleOptions
type AmqpModuleOptions<TContract, HandlersError, HandlersNeeds, I, P, X> = object;Defined in: amqp/src/amqp-module.ts:39
Type Parameters
| Type Parameter |
|---|
TContract extends AnyAmqpContract |
HandlersError |
HandlersNeeds |
I extends readonly AnyModule[] |
P extends readonly AnyProvider[] |
X extends readonly Exportable<Imports<I, TContract>, Provides<P, TContract, HandlersError, HandlersNeeds>>[] |
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
connectionOptions? | readonly | Record<string, unknown> | - | amqp/src/amqp-module.ts:55 |
connectTimeoutMs? | readonly | number | See AmqpOptions.connectTimeoutMs. | amqp/src/amqp-module.ts:58 |
contract | readonly | TContract | - | amqp/src/amqp-module.ts:50 |
defaultConsumerOptions? | readonly | Record<string, unknown> | - | amqp/src/amqp-module.ts:56 |
exports? | readonly | X | The application's own exports; AmqpRuntime is added, since start resolves it. | amqp/src/amqp-module.ts:62 |
handlers | readonly | Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds> | The application's handlers — AmqpHandlers(contract)(deps, arm), one per consumers / rpcs key of THIS contract, as the provider that builds them from the services they call. | amqp/src/amqp-module.ts:52 |
imports? | readonly | I | - | amqp/src/amqp-module.ts:59 |
provides? | readonly | P | - | amqp/src/amqp-module.ts:60 |
url? | readonly | string | Pins the broker instead of reading AMQP_URL — a test's container. | amqp/src/amqp-module.ts:54 |
AmqpOptions
type AmqpOptions<TContract> = object;Defined in: amqp/src/amqp-runtime.ts:68
Type Parameters
| Type Parameter |
|---|
TContract extends AnyAmqpContract |
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
connectionOptions? | readonly | Record<string, unknown> | - | amqp/src/amqp-runtime.ts:79 |
connectTimeoutMs? | readonly | number | How long create waits for the connection before failing. Passed straight through — it is a top-level CreateWorkerOptions field, NOT nested under connectionOptions, where setting it is silently inert. Without it an unreachable broker takes the library's 30s default to report. | amqp/src/amqp-runtime.ts:87 |
contract | readonly | TContract | The contract; the handlers port is typed by it — one handler per consumers / rpcs key, WorkerInferHandlers<TContract> with no injected context (a handler is built by di from the services it declares, so there is no context for the middleware to hand it) — and the composition root provides it through AmqpHandlers(contract)(deps, arm). | amqp/src/amqp-runtime.ts:76 |
defaultConsumerOptions? | readonly | Record<string, unknown> | - | amqp/src/amqp-runtime.ts:80 |
url? | readonly | string | Pins the broker instead of reading AMQP_URL — a test's container. | amqp/src/amqp-runtime.ts:78 |
HandlerPortOf
type HandlerPortOf<C, K> = PortClassOf<`${typeof HANDLER_PREFIX}${K}`, WorkerInferHandlers<C>[K]>;Defined in: amqp/src/handler.ts:14
The port one piece targets. Its id carries the contract key, which is what makes two slices claiming one consumer di's duplicate-provider defect rather than a silent merge.
Type Parameters
| Type Parameter |
|---|
C extends AnyAmqpContract |
K extends HandlerKeyOf<C> |
HandlersInstanceOf
type HandlersInstanceOf<C> = PortInstance<"AmqpHandlers", WorkerInferHandlers<C>>;Defined in: amqp/src/amqp-runtime.ts:63
The handlers port's instance for C — the module's one need.
Type Parameters
| Type Parameter |
|---|
C extends AnyAmqpContract |
HandlersPortOf
type HandlersPortOf<C> = PortClassOf<"AmqpHandlers", WorkerInferHandlers<C>>;Defined in: amqp/src/amqp-runtime.ts:57
The handlers port class, typed for C: what AmqpHandlers(contract)(…).port is.
Type Parameters
| Type Parameter |
|---|
C extends AnyAmqpContract |
Functions
amqp()
function amqp<TContract>(options): Module<AmqpRuntime | AmqpConfig, ConfigInvalid, Env | HandlersInstanceOf<TContract>>;Defined in: amqp/src/amqp-runtime.ts:103
The AMQP starter: a module providing the runtime (AmqpRuntime) and its configuration (AmqpConfig, bound from AMQP_URL unless pinned here), built over the handlers the application provides on the starter's own handlers port (AmqpHandlers(contract)(deps, arm)). Import it next to the application, provide the handlers, export AmqpRuntime — that is the whole of the transport wiring. The handlers port is the module's one need, which di's own gate checks where the composition root is declared.
With url pinned the module reads nothing from the environment (the declared Env need and ConfigInvalid stay — the kernel discharges the one, a pinned config never produces the other).
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Parameters
| Parameter | Type |
|---|---|
options | AmqpOptions<TContract> |
Returns
Module<AmqpRuntime | AmqpConfig, ConfigInvalid, Env | HandlersInstanceOf<TContract>>
AmqpHandler()
function AmqpHandler<C, K>(contract, key): {
<D, O> (deps, options): Provider<PortInstance<`AmqpHandler:${K}`, WorkerInferHandlers<C>[K]>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object;
<O> (options): Provider<PortInstance<`AmqpHandler:${K}`, WorkerInferHandlers<C>[K]>, ErrorOf<O>, ScopeOf<O>> & object;
};Defined in: amqp/src/handler.ts:36
One consumer or rpc of a contract, as a provider on a port of its own.
A worker with several consumers is several pieces, each declaring the services its own handler calls; AmqpHandlers(contract)([...]) composes them. contract is read for its type only — it is what types key and the handler, so a consumer the contract does not declare, or a handler whose message has drifted, is a compile error here rather than at the root.
There is no name to give: the contract key IS the port's name. The port is minted for you and carried back on provider.port, and the return is di's own Provider(port), so every arm — value / sync / make / class / acquire — is available exactly as it is on AmqpHandlers(contract).
Type Parameters
| Type Parameter |
|---|
C extends ContractDefinition |
K extends string |
Parameters
| Parameter | Type |
|---|---|
contract | C |
key | K |
Returns
{ <D, O> (deps, options): Provider<PortInstance<`AmqpHandler:${K}`, WorkerInferHandlers<C>[K]>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object; <O> (options): Provider<PortInstance<`AmqpHandler:${K}`, WorkerInferHandlers<C>[K]>, ErrorOf<O>, ScopeOf<O>> & object; }
AmqpHandlers()
function AmqpHandlers<C>(contract): {
<D, O> (deps, options): Provider<PortInstance<"AmqpHandlers", WorkerInferHandlers<C>>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object;
<O> (options): Provider<PortInstance<"AmqpHandlers", WorkerInferHandlers<C>>, ErrorOf<O>, ScopeOf<O>> & object;
} & Compose<C>;Defined in: amqp/src/amqp-runtime.ts:181
The handlers as a provider, from the contract. Three call forms, one port.
AmqpHandlers(orderContract)([Logger], { sync: (logger) => ({ orderNotifications: (m) => … }) })
AmqpHandlers(orderContract)([orderNotifications, orderAudit])The first two are di's own Provider(port) on the starter's handlers port typed for the contract — any arm, same typing, checked against the record before any module sees it. The third takes the piecesAmqpHandler(contract, key) builds, one per consumer or rpc: di constructs every piece first (they are the provider's deps, in array order) and this reassembles the record from them. Every key the contract declares must be covered, and two slices claiming one key are two providers for one port — di's duplicate-provider defect at build, which is the point.
There is no name to give: a consumer serves one handlers record, so the port is the starter's, and the provider carries it typed (orderHandlers.port).
Type Parameters
| Type Parameter |
|---|
C extends ContractDefinition |
Parameters
| Parameter | Type |
|---|---|
contract | C |
Returns
{ <D, O> (deps, options): Provider<PortInstance<"AmqpHandlers", WorkerInferHandlers<C>>, ErrorOf<O>, InstanceType<D[number]> | ScopeOf<O>> & object; <O> (options): Provider<PortInstance<"AmqpHandlers", WorkerInferHandlers<C>>, ErrorOf<O>, ScopeOf<O>> & object; } & Compose<C>
AmqpModule()
function AmqpModule<Name>(name): <TContract, HandlersError, HandlersNeeds, I, P, X>(options) => Module<ResolvedExports<readonly [typeof AmqpRuntime, X]>,
| ErrOf<readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P][number]>
| ErrOfModule<readonly [I, AmqpStarter<TContract>][number]>,
| Exclude<NeedOf<readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P][number]>, Available<readonly [I, AmqpStarter<TContract>], readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P]>>
| Exclude<NeedsOfModule<readonly [I, AmqpStarter<TContract>][number]>, Available<readonly [I, AmqpStarter<TContract>], readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P]>>>;Defined in: amqp/src/amqp-module.ts:87
Module(name)({...}) for an AMQP deployment: everything a di module takes, plus the contract and the handlers provider, and nothing else to know. The sugar imports the starter (amqp({ contract })), provides the handlers, and exports AmqpRuntime — so a root that would otherwise write those two lines and remember that start needs the runtime exported writes neither. It hands back exactly the module Module(...) would have declared over the augmented imports/provides/exports (spelled from di's own pieces), so the kernel, start's gate and di's see nothing new: syntax over the same primitives, one source of truth.
export const OrderAmqpWorker = AmqpModule("OrderAmqpWorker")({
contract: orderContract,
handlers: orderHandlers,
imports: [OrderApplicationModule, OrderPersistenceModule],
exports: [Logger],
});
await runMain(OrderAmqpWorker);Type Parameters
| Type Parameter |
|---|
Name extends string |
Parameters
| Parameter | Type |
|---|---|
name | Name |
Returns
<TContract, HandlersError, HandlersNeeds, I, P, X>(options) => Module<ResolvedExports<readonly [typeof AmqpRuntime, X]>, | ErrOf<readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P][number]> | ErrOfModule<readonly [I, AmqpStarter<TContract>][number]>, | Exclude<NeedOf<readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P][number]>, Available<readonly [I, AmqpStarter<TContract>], readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P]>> | Exclude<NeedsOfModule<readonly [I, AmqpStarter<TContract>][number]>, Available<readonly [I, AmqpStarter<TContract>], readonly [Provider<HandlersInstanceOf<TContract>, HandlersError, HandlersNeeds>, P]>>>