Connectum API Reference / @connectum/events-amqp / types / AmqpAdapterOptions
Interface: AmqpAdapterOptions
Defined in: packages/events-amqp/src/types.ts:10
Options for creating an AMQP/RabbitMQ adapter.
Properties
consumerOptions?
readonlyoptionalconsumerOptions?:AmqpConsumerOptions
Defined in: packages/events-amqp/src/types.ts:50
Consumer options.
exchange?
readonlyoptionalexchange?:string
Defined in: packages/events-amqp/src/types.ts:28
Exchange name for publishing and subscribing.
Default
"connectum.events"exchangeOptions?
readonlyoptionalexchangeOptions?:AmqpExchangeOptions
Defined in: packages/events-amqp/src/types.ts:40
Exchange assertion options.
exchangeType?
readonlyoptionalexchangeType?:"headers"|"topic"|"direct"|"fanout"
Defined in: packages/events-amqp/src/types.ts:35
Exchange type.
Default
"topic"failFastOnInitialSetupError?
readonlyoptionalfailFastOnInitialSetupError?:boolean
Defined in: packages/events-amqp/src/types.ts:152
Fail fast on a DETERMINISTIC setup/topology error on the FIRST connect, instead of entering amqplib's infinite recovery loop.
amqplib's opt-in recovery resolves connect() only after its setup hook succeeds, and rejects only once maxRetries is exhausted (default Infinity). A permanent topology error on the first connect under the default recovery therefore HANGS connect() forever, with no thrown error and — because the lifecycle listeners attach only after that never-returning await — no callback. When this flag is true (and recovery is enabled), the adapter first validates topology against a throwaway non-recovering connection; a topology error rejects connect() with the typed AmqpTopologyError / AmqpConnectionError.
Only deterministic setup/topology errors fail fast. A transient broker-unreachable at startup is NOT a fail-fast condition — it falls through to normal recovery (block-until-broker). SUBSEQUENT reconnects always keep infinite-recovery behavior.
No-op with recovery: false (that path already fails fast on setup). Enabling this — or supplying AmqpLifecycleCallbacks.onLifecycle or AmqpLifecycleCallbacks.onSetupFailed — adds one extra short-lived connection plus a topology validation pass at startup for the probe (recovery must be enabled; with recovery: false no probe runs and no setup-failed event is delivered).
Default
falselifecycle?
readonlyoptionallifecycle?:AmqpLifecycleCallbacks
Defined in: packages/events-amqp/src/types.ts:249
Connection lifecycle callbacks. Connection errors are surfaced here — not just logged.
publisherOptions?
readonlyoptionalpublisherOptions?:AmqpPublisherOptions
Defined in: packages/events-amqp/src/types.ts:55
Publisher options.
publishRetry?
readonlyoptionalpublishRetry?:boolean|AmqpPublishRetryOptions
Defined in: packages/events-amqp/src/types.ts:243
Opt-in bounded publish retry for CONNECTION-CLASS outcomes (since 1.3.0).
When enabled, a publish() that fails with AmqpConnectionError — publishing during a recovery window, or an in-flight confirm lost to a connection drop — is retried in place (the caller's promise stays pending) instead of rejecting immediately: a short broker blip becomes a transparent delay. true = defaults; an object tunes the budget.
The retry boundary is isAutoRetriablePublishError — deliberately NARROWER than the at-least-once republish matrix in the error taxonomy: a broker nack is republish-safe by policy but is NOT auto-retried inline (it is an explicit broker refusal, e.g. an over-capacity queue — hammering it in a tight loop helps nobody). AmqpPublishTimeoutError joins the boundary only with retryOnTimeout: true.
Semantics — read before enabling:
- At-least-once, full stop. A retried publish whose previous attempt was lost IN FLIGHT (confirm never arrived: state UNKNOWN) may duplicate on the broker.
x-event-id/messageIdstay STABLE across attempts (also withexternalContract— a caller-supplied id is reused as-is), so consumer-side dedup keys on them. - Worst-case latency: each attempt is bounded by
publishTimeoutMs(default 30s), somaxRetries: 5can hold a singlepublish()for several minutes worst-case — far beyond typical 30s RPC timeouts. There is deliberately no second overall-deadline knob: bound the budget viamaxRetries/publishTimeoutMs. - Shutdown-aware: the loop aborts on
disconnect()(throws the last connection error) and, living inside theadapter.publish()promise, is automatically covered by the bus-leveldrainPublishTimeout. - Single-flight (
mandatory: truewithcorrelationHeader: false;externalContractforces the latter but single-flight still requiresmandatory): retries hold the chain — ordering is preserved at the cost of head-of-line blocking during backoff. In this headerless mode a latebasic.returnfrom an abandoned timed-out attempt may mark the current one (correlation is attempt-agnostic without the header) — prefer the default header correlation when combiningmandatorywithretryOnTimeout. - Deterministic channel-close is not retried: a broker reply with a
404/406code that killed the publish CHANNEL (e.g. a publish to a missing exchange undertopologyMode: "skip") surfaces immediately with the broker reply ascause— the connection stays up, recovery never recreates the channel, so retrying cannot heal.
Backoff mirrors the recovery formula (same knob names and semantics, incl. cap-before-jitter), but the DEFAULT budget differs: maxRetries here defaults to 5 (bounded), not Infinity.
Default
undefined (disabled — behavior unchanged)publishTimeoutMs?
readonlyoptionalpublishTimeoutMs?:number
Defined in: packages/events-amqp/src/types.ts:259
Per-publish broker-outcome deadline in milliseconds. A publish whose ack/nack/return/connection-loss outcome does not arrive in time rejects with AmqpPublishTimeoutError (message state UNKNOWN — an at-least-once producer should republish).
Default
30000queueOptions?
readonlyoptionalqueueOptions?:AmqpQueueOptions
Defined in: packages/events-amqp/src/types.ts:45
Default queue assertion options.
queueOverrides?
readonlyoptionalqueueOverrides?:Record<string,AmqpQueueOverride>
Defined in: packages/events-amqp/src/types.ts:101
Map a consumer group name to an externally-named queue.
By default a group consumes from ${exchange}.${group}. An override lets a subscription attach to a queue from an external contract (with its own arguments) instead.
recovery?
readonlyoptionalrecovery?:boolean|AmqpRecoveryOptions
Defined in: packages/events-amqp/src/types.ts:122
Automatic connection recovery (delegated to amqplib's opt-in recovery). Enabled by default; pass false to restore no-reconnect behavior.
On every (re)connect the adapter re-creates its channels, re-applies topology (per topologyMode), and replays active subscriptions. In-flight publishes at the moment of a connection loss reject with AmqpConnectionError.
maxRetries governs BOTH the initial connect and steady-state recovery (counter reset on success); under the default Infinity, connect() blocks until the broker is reachable rather than failing fast (see AmqpAdapterOptions.failFastOnInitialSetupError to fail fast on a deterministic startup misconfiguration). See AmqpRecoveryOptions for the retry-budget scope and jitter/maxDelay overshoot.
Default
true (amqplib defaults: 100ms initial, ×2, 30s cap, jitter 0.2, infinite retries)serialization?
readonlyoptionalserialization?:AmqpSerializationOptions
Defined in: packages/events-amqp/src/types.ts:66
Message serialization metadata and optional wire transcoding.
The adapter receives payloads as bytes (the EventBus serializes protobuf upstream); this option controls the AMQP contentType property and lets an application transcode the wire body — e.g. when the application serializes JSON itself and publishes through the adapter directly against an external AsyncAPI contract.
socketOptions?
readonlyoptionalsocketOptions?:Record<string,unknown>
Defined in: packages/events-amqp/src/types.ts:21
Socket options passed to amqplib.connect().
topology?
readonlyoptionaltopology?:AmqpTopology
Defined in: packages/events-amqp/src/types.ts:74
Explicit topology to declare on connect (and re-declare after recovery): exchanges, queues with arbitrary external names and raw arguments (e.g. x-dead-letter-exchange), and bindings — including exchange-to-exchange.
topologyMode?
readonlyoptionaltopologyMode?:AmqpTopologyMode
Defined in: packages/events-amqp/src/types.ts:92
How topology is established:
"assert"(default) — declare idempotently (assertExchange/assertQueue/bind);"check"— existence-only verification (checkExchange/checkQueue). A missing object raises AmqpTopologyError, which failsconnect()fast ONLY withrecovery: falseorfailFastOnInitialSetupError: true; under the default recovery a first-connect check failure otherwise enters the (infinite) recovery loop and is surfaced viaonSetupFailed/onReconnectingrather than rejectingconnect(). AMQP offers no passive introspection: argument equivalence and binding presence are NOT verifiable in this mode (a conflicting redeclare elsewhere is PRECONDITION_FAILED 406);"skip"— no topology operations at all; the application owns topology.
Default
"assert"treatTopologyErrorAsFatal?
readonlyoptionaltreatTopologyErrorAsFatal?:boolean
Defined in: packages/events-amqp/src/types.ts:191
Treat DETERMINISTIC topology drift during steady-state recovery as fatal: stop the reconnect cycle instead of retrying forever against a misconfigured broker.
Under the default maxRetries: Infinity, a queue/exchange deleted or redeclared incompatibly while the adapter is reconnecting makes every recovery attempt fail deterministically — the adapter would retry forever, reporting setup-failed on each attempt but never giving up. With this flag the adapter stops the cycle on the first such failure and reports the terminal reconnect-failed lifecycle event (after the setup-failed event for the same attempt); subsequent publishes fail fast with AmqpConnectionError.
The gate is the AMQP reply code of the failure cause — 404 (NOT_FOUND) or 406 (PRECONDITION_FAILED) — NOT the error class: transient causes wrapped into AmqpTopologyError during a setup pass (broker restarting 320, internal error 541, resource locked 405, a mid-setup connection drop) stay in normal recovery. One known transient 404 is excluded explicitly: a RabbitMQ cluster classic queue whose home node is down ("... down or inaccessible") stays in recovery.
After the fatal stop the adapter is fully torn down: consumers are dead (subscription records are cleared, mirroring disconnect()), publishes fail fast, and a later connect() starts from a clean slate — re-subscribe explicitly.
Scope: steady-state recovery only. Boot-time drift is the startup probe's job — see failFastOnInitialSetupError. Setting both covers boot and steady state; the remaining window — broker unreachable at connect() time with drift surfacing before the first successful connect — is closed by AmqpRecoveryOptions.initialConnectMaxRetries (since 1.3.0), whose bounded phase surfaces those failures and rejects on exhaustion.
Default
falseurl
readonlyurl:string
Defined in: packages/events-amqp/src/types.ts:16
AMQP connection URL.
Example
"amqp://guest:guest@localhost:5672"