Skip to content

Send / Publish / Request / Reply Options

Every outgoing call on the Bus takes a small, purpose-built options object. They share the same headers shape (an immutable record of string-to-string custom headers) but otherwise capture exactly what each call needs — an endpoint for send, a routing key for publish, a timeout and optional signal for requests, headers only for replies.

import { DEFAULT_REQUEST_TIMEOUT_MS } from '@serviceconnect/core';
import type {
PublishOptions,
ReplyOptions,
RequestOptions,
SendOptions,
} from '@serviceconnect/core';
export interface SendOptions {
readonly headers?: Readonly<Record<string, string>>;
readonly endpoint: string;
}
  • endpoint (required) — the destination queue / endpoint name to send to. Stamped onto the outgoing envelope as destinationAddress.
  • headers (optional) — extra string-valued headers merged into the envelope before the outgoing pipeline runs. Bus-managed headers messageType, sourceAddress, and timeSent are stamped unconditionally and override any caller-supplied value (destinationAddress is set from endpoint). messageId is the exception: a caller-supplied messageId is kept, and the bus only auto-generates one when it is absent. correlationId is not a header — it travels on the message body — so it is not stamped here.
export interface PublishOptions {
readonly headers?: Readonly<Record<string, string>>;
readonly routingKey?: string;
}
  • routingKey (optional) — the broker-level routing key. With RabbitMQ this maps to AMQP’s routing key on the type’s exchange; with other transports it is interpreted by the adapter.
  • headers (optional) — same semantics as SendOptions.headers.
export interface RequestOptions {
readonly headers?: Readonly<Record<string, string>>;
readonly endpoint?: string;
readonly timeoutMs?: number;
readonly expectedReplyCount?: number;
readonly signal?: AbortSignal;
}
  • endpoint (optional) — point-to-point destination. If omitted the request is published; if set it is sent.
  • timeoutMs (optional, required for sendRequest) — milliseconds before the pending request rejects with RequestTimeoutError (or, for sendRequestMulti, resolves with however many replies arrived).
  • expectedReplyCount (optional) — used by sendRequestMulti to short-circuit once the expected number of replies has arrived without waiting for the full timeout.
  • signal (optional) — caller-supplied AbortSignal. When the signal aborts before a reply arrives the request rejects with AbortError.
  • headers (optional) — extra headers merged into the outgoing request envelope.
export interface ReplyOptions {
readonly headers?: Readonly<Record<string, string>>;
}
  • headers (optional) — extra headers merged into the reply envelope. The reply already stamps responseMessageId (echoing the inbound request’s requestMessageId) and destinationAddress (the inbound request’s sourceAddress), so you only need this for application-specific headers.
export const DEFAULT_REQUEST_TIMEOUT_MS = 10_000;

The default request timeout in milliseconds (10_000). It documents the intended default, but the bus does not actually read this exported constant: the only code path that applies a default — publishRequest — inlines the literal 10_000 independently. BusOptions.defaultRequestTimeout is currently inert (declared but never consumed) and plays no part in any fallback. sendRequest and sendRequestMulti apply no default at all — they require a positive timeoutMs on the call site and otherwise throw ArgumentOutOfRangeError.