@amqp-contract/client
@amqp-contract/client
Classes
MessageValidationError
Defined in: packages/core/dist/index.d.mts:27
Error thrown when message validation fails (payload or headers).
Used by both the client (publish-time payload validation) and the worker (consume-time payload and headers validation).
Param
The name of the publisher or consumer that triggered the validation
Param
The validation issues from the Standard Schema validation
Extends
Error
Constructors
Constructor
new MessageValidationError(source, issues): MessageValidationError;Defined in: packages/core/dist/index.d.mts:30
Parameters
| Parameter | Type |
|---|---|
source | string |
issues | unknown |
Returns
Overrides
Error.constructorProperties
Methods
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:52
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Error.captureStackTraceprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:56
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTraceRpcCancelledError
Defined in: packages/client/src/errors.ts:39
Returned from any in-flight RPC call when the client is closed before the reply is received. The correlation map is cleared on close and every pending caller's promise resolves with err(RpcCancelledError).
Extends
Error
Constructors
Constructor
new RpcCancelledError(rpcName): RpcCancelledError;Defined in: packages/client/src/errors.ts:40
Parameters
| Parameter | Type |
|---|---|
rpcName | string |
Returns
Overrides
Error.constructorProperties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | public | unknown | - | Error.cause | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24 |
message | public | string | - | Error.message | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075 |
name | public | string | - | Error.name | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074 |
rpcName | readonly | string | - | - | packages/client/src/errors.ts:40 |
stack? | public | string | - | Error.stack | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | Error.stackTraceLimit | node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:68 |
Methods
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:52
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Error.captureStackTraceprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:56
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTraceRpcTimeoutError
Defined in: packages/client/src/errors.ts:23
Returned from TypedAmqpClient.call() when the configured timeoutMs elapses before the RPC server publishes a reply with the matching correlationId.
The pending call is removed from the in-memory correlation map; if a reply arrives after the timeout it is dropped (and a debug log is emitted by the client if a logger is configured).
Extends
Error
Constructors
Constructor
new RpcTimeoutError(rpcName, timeoutMs): RpcTimeoutError;Defined in: packages/client/src/errors.ts:24
Parameters
| Parameter | Type |
|---|---|
rpcName | string |
timeoutMs | number |
Returns
Overrides
Error.constructorProperties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | public | unknown | - | Error.cause | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24 |
message | public | string | - | Error.message | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075 |
name | public | string | - | Error.name | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074 |
rpcName | readonly | string | - | - | packages/client/src/errors.ts:25 |
stack? | public | string | - | Error.stack | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |
timeoutMs | readonly | number | - | - | packages/client/src/errors.ts:26 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | Error.stackTraceLimit | node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:68 |
Methods
captureStackTrace()
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:52
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Error.captureStackTraceprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/.pnpm/@types+node@24.12.2/node_modules/@types/node/globals.d.ts:56
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTraceTypedAmqpClient
Defined in: packages/client/src/client.ts:125
Type-safe AMQP client for publishing messages
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Methods
call()
call<TName>(
rpcName,
request,
options): ResultAsync<ClientInferRpcResponseOutput<TContract, TName>,
| TechnicalError
| MessageValidationError
| RpcTimeoutError
| RpcCancelledError>;Defined in: packages/client/src/client.ts:406
Invoke an RPC defined via defineRpc and await the typed response.
The request payload is validated against the RPC's request schema, then published to the AMQP default exchange with the server's queue name as routing key, replyTo set to amq.rabbitmq.reply-to, and a fresh UUID correlationId. The returned ResultAsync resolves once a matching reply arrives and validates against the response schema, or once timeoutMs elapses (whichever comes first).
Type Parameters
| Type Parameter |
|---|
TName extends string | number | symbol |
Parameters
| Parameter | Type |
|---|---|
rpcName | TName |
request | ClientInferRpcRequestInput<TContract, TName> |
options | CallOptions |
Returns
ResultAsync<ClientInferRpcResponseOutput<TContract, TName>, | TechnicalError | MessageValidationError | RpcTimeoutError | RpcCancelledError>
Example
const result = await client.call('calculate', { a: 1, b: 2 }, { timeoutMs: 5_000 });
if (result.isOk()) console.log(result.value.sum); // 3close()
close(): ResultAsync<void, TechnicalError>;Defined in: packages/client/src/client.ts:556
Close the channel and connection. Cancels the reply consumer (if any) and rejects every in-flight RPC call with RpcCancelledError.
Returns
ResultAsync<void, TechnicalError>
publish()
publish<TName>(
publisherName,
message,
options?): ResultAsync<void, TechnicalError | MessageValidationError>;Defined in: packages/client/src/client.ts:298
Publish a message using a defined publisher.
Type Parameters
| Type Parameter |
|---|
TName extends string | number | symbol |
Parameters
| Parameter | Type | Description |
|---|---|---|
publisherName | TName | The name of the publisher to use |
message | ClientInferPublisherInput<TContract, TName> | The message to publish |
options? | PublishOptions | Optional publish options including compression, headers, priority, etc. |
Returns
ResultAsync<void, TechnicalError | MessageValidationError>
Remarks
If options.compression is specified, the message will be compressed before publishing and the contentEncoding property will be set automatically. Any contentEncoding value already in options will be overwritten by the compression algorithm.
create()
static create<TContract>(__namedParameters): ResultAsync<TypedAmqpClient<TContract>, TechnicalError>;Defined in: packages/client/src/client.ts:156
Create a type-safe AMQP client from a contract.
Connection management (including automatic reconnection) is handled internally by amqp-connection-manager via the AmqpClient. The client establishes infrastructure asynchronously in the background once the connection is ready.
Connections are automatically shared across clients with the same URLs and connection options, following RabbitMQ best practices.
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Parameters
| Parameter | Type |
|---|---|
__namedParameters | CreateClientOptions<TContract> |
Returns
ResultAsync<TypedAmqpClient<TContract>, TechnicalError>
Type Aliases
CallOptions
type CallOptions = object;Defined in: packages/client/src/client.ts:105
Per-call options for client.call().
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
publishOptions? | Omit<AmqpClientPublishOptions, "replyTo" | "correlationId"> | Optional AMQP message properties to merge into the request. replyTo and correlationId are managed by the client and cannot be overridden. | packages/client/src/client.ts:119 |
timeoutMs | number | Maximum time in ms to wait for an RPC reply. If exceeded, the call resolves to err(RpcTimeoutError) and the in-memory correlation entry is cleared. A late reply arriving after the timeout is silently dropped. Required: RPC without a timeout is a footgun. | packages/client/src/client.ts:113 |
ClientInferPublisherInput
type ClientInferPublisherInput<TContract, TName> = PublisherInferInput<InferPublisher<TContract, TName>>;Defined in: packages/client/src/types.ts:43
Input type accepted by client.publish(name, ...) for a specific publisher.
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
TName extends InferPublisherNames<TContract> |
ClientInferRpcRequestInput
type ClientInferRpcRequestInput<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<infer TRequest, MessageDefinition> ? TRequest extends MessageDefinition ? InferSchemaInput<TRequest["payload"]> : never : never;Defined in: packages/client/src/types.ts:61
Input type accepted by client.call(name, request, ...).
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
TName extends InferRpcNames<TContract> |
ClientInferRpcResponseOutput
type ClientInferRpcResponseOutput<TContract, TName> = InferRpc<TContract, TName> extends RpcDefinition<MessageDefinition, infer TResponse> ? TResponse extends MessageDefinition ? InferSchemaOutput<TResponse["payload"]> : never : never;Defined in: packages/client/src/types.ts:74
Output (validated) response type returned by client.call(name, ...).
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
TName extends InferRpcNames<TContract> |
CreateClientOptions
type CreateClientOptions<TContract> = object;Defined in: packages/client/src/client.ts:76
Options for creating a client
Type Parameters
| Type Parameter |
|---|
TContract extends ContractDefinition |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
connectionOptions? | AmqpConnectionManagerOptions | - | packages/client/src/client.ts:79 |
connectTimeoutMs? | number | null | Maximum time in ms to wait for the AMQP connection to become ready before create() resolves to an err(TechnicalError). Defaults to 30s (the AmqpClient's DEFAULT_CONNECT_TIMEOUT_MS). Pass null to disable the timeout and let amqp-connection-manager retry indefinitely. | packages/client/src/client.ts:99 |
contract | TContract | - | packages/client/src/client.ts:77 |
defaultPublishOptions? | PublishOptions | Default publish options that will be applied to all publish operations. These can be overridden by options passed to the publish method. By default, persistent is set to true for message durability. | packages/client/src/client.ts:92 |
logger? | Logger | - | packages/client/src/client.ts:80 |
telemetry? | TelemetryProvider | Optional telemetry provider for tracing and metrics. If not provided, uses the default provider which attempts to load OpenTelemetry. OpenTelemetry instrumentation is automatically enabled if @opentelemetry/api is installed. | packages/client/src/client.ts:86 |
urls | ConnectionUrl[] | - | packages/client/src/client.ts:78 |
PublishOptions
type PublishOptions = AmqpClientPublishOptions & object;Defined in: packages/client/src/client.ts:64
Publish options that extend amqp-client's PublishOptions with optional compression support.
Type Declaration
| Name | Type | Description | Defined in |
|---|---|---|---|
compression? | CompressionAlgorithm | Optional compression algorithm to use for the message payload. When specified, the message will be compressed using the chosen algorithm and the contentEncoding header will be set automatically. | packages/client/src/client.ts:70 |