vael:amqp
Async AMQP 0-9-1 messaging client (vael:amqp).
Available in the vjs (vaeljs) runtime only when built with the opt-in
vael-amqp (or vael-messaging) Cargo feature; absent in default builds
and in vjs-lite.
import ... from "vael:amqp"
vael-amqp / vael-messaging (opt-in in vaeljs-core, disabled by default; absent in vaeljs-lite-core)Example
Section titled “Example”import { connect } from "vael:amqp";
const conn = await connect({ host: "127.0.0.1", port: 5672 });const ch = await conn.createChannel();try { await ch.declareQueue("tasks", { durable: true }); await ch.publish("", "tasks", "hello");} finally { await ch.close(); await conn.close();}AmqpConnectOptionsvjs onlyv0.0.0-alpha.2connect(options).AmqpExchangeOptionsvjs onlyv0.0.0-alpha.2AmqpChannel.declareExchange().AmqpDeleteExchangeOptionsvjs onlyv0.0.0-alpha.2AmqpChannel.deleteExchange().AmqpQueueOptionsvjs onlyv0.0.0-alpha.2AmqpChannel.declareQueue().AmqpDeleteQueueOptionsvjs onlyv0.0.0-alpha.2AmqpChannel.deleteQueue().AmqpMessagePropertiesvjs onlyv0.0.0-alpha.2AmqpPublishOptionsvjs onlyv0.0.0-alpha.2AmqpChannel.publish().AmqpConsumeOptionsvjs onlyv0.0.0-alpha.2AmqpChannel.consume().AmqpMessagevjs onlyv0.0.0-alpha.2AmqpChannel.get() or AmqpChannel.consume().AmqpChannelvjs onlyv0.0.0-alpha.2AmqpConnection.createChannel().AmqpConnectionvjs onlyv0.0.0-alpha.2connect().Functions
Section titled “Functions”connect
Section titled “connect”export function connect(options: AmqpConnectOptions): Promise<AmqpConnection>;
Connect asynchronously to an AMQP 0-9-1 broker (vael-amqp feature required).
| Name | Type | Description |
|---|---|---|
options | AmqpConnectOptions | AMQP connection configuration. |
Promise<AmqpConnection> — Promise resolving to a connected AmqpConnection.TypeError— on invalid argument types.AmqpError— on connection, authentication, TLS, or timeout failures.
Classes
Section titled “Classes”AmqpError
Section titled “AmqpError”export class AmqpError extends Error {
override name: "AmqpError";
code: AmqpErrorCode;
constructor(code: AmqpErrorCode, message: string);
}
Redacted AMQP client error carrying a stable AmqpErrorCode.
constructor(code: AmqpErrorCode, message: string);
Construct an AmqpError.
| Name | Type | Description |
|---|---|---|
code | AmqpErrorCode | Machine-readable AmqpErrorCode. |
message | string | Human-readable redacted error description. |
| Property | Type | Description | Since |
|---|---|---|---|
name | "AmqpError" | Error name ("AmqpError"). | v0.0.0-alpha.2 |
code | AmqpErrorCode | Machine-readable AMQP error code. | v0.0.0-alpha.2 |
Interfaces
Section titled “Interfaces”AmqpConnectOptions
Section titled “AmqpConnectOptions”export interface AmqpConnectOptions {
host: string;
port?: number;
vhost?: string;
username?: string;
password?: string;
tls?: boolean;
heartbeatSecs?: number;
frameMax?: number;
connectTimeoutMs?: number;
commandTimeoutMs?: number;
}
Connection configuration accepted by connect(options).
| Property | Type | Description | Since |
|---|---|---|---|
host | string | Broker hostname or IP address (required). | v0.0.0-alpha.2 |
port optional | number | Broker TCP port (1..=65535, default 5672 or 5671 when tls: true). | v0.0.0-alpha.2 |
vhost optional | string | Virtual host name (default "/"). | v0.0.0-alpha.2 |
username optional | string | Authentication username (default "guest"). | v0.0.0-alpha.2 |
password optional | string | Authentication password (default "guest"). | v0.0.0-alpha.2 |
tls optional | boolean | Enable fail-closed rustls TLS transport (default false). | v0.0.0-alpha.2 |
heartbeatSecs optional | number | AMQP heartbeat interval in seconds (0..=65535). | v0.0.0-alpha.2 |
frameMax optional | number | Maximum AMQP frame size in bytes (4096..=16777216). | v0.0.0-alpha.2 |
connectTimeoutMs optional | number | TCP/TLS/handshake connect timeout in milliseconds (1..=300000). | v0.0.0-alpha.2 |
commandTimeoutMs optional | number | Per-RPC command timeout in milliseconds (1..=300000). | v0.0.0-alpha.2 |
AmqpExchangeOptions
Section titled “AmqpExchangeOptions”export interface AmqpExchangeOptions {
passive?: boolean;
durable?: boolean;
autoDelete?: boolean;
internal?: boolean;
nowait?: boolean;
arguments?: Record<string, unknown>;
}
Options accepted by AmqpChannel.declareExchange().
| Property | Type | Description | Since |
|---|---|---|---|
passive optional | boolean | Fail if the exchange does not already exist instead of creating it. | v0.0.0-alpha.2 |
durable optional | boolean | Persist exchange definition across broker restarts. | v0.0.0-alpha.2 |
autoDelete optional | boolean | Delete exchange when the last queue unbinds. | v0.0.0-alpha.2 |
internal optional | boolean | Mark exchange as internal (cannot be directly published to). | v0.0.0-alpha.2 |
nowait optional | boolean | Do not wait for broker Exchange.DeclareOk reply. | v0.0.0-alpha.2 |
arguments optional | Record<string, unknown> | Optional AMQP field-table extension arguments. | v0.0.0-alpha.2 |
AmqpDeleteExchangeOptions
Section titled “AmqpDeleteExchangeOptions”export interface AmqpDeleteExchangeOptions {
ifUnused?: boolean;
nowait?: boolean;
}
Options accepted by AmqpChannel.deleteExchange().
| Property | Type | Description | Since |
|---|---|---|---|
ifUnused optional | boolean | Only delete if exchange currently has no queue bindings. | v0.0.0-alpha.2 |
nowait optional | boolean | Do not wait for broker Exchange.DeleteOk reply. | v0.0.0-alpha.2 |
AmqpQueueOptions
Section titled “AmqpQueueOptions”export interface AmqpQueueOptions {
passive?: boolean;
durable?: boolean;
exclusive?: boolean;
autoDelete?: boolean;
nowait?: boolean;
arguments?: Record<string, unknown>;
}
Options accepted by AmqpChannel.declareQueue().
| Property | Type | Description | Since |
|---|---|---|---|
passive optional | boolean | Check queue existence without modifying or creating it. | v0.0.0-alpha.2 |
durable optional | boolean | Persist queue across broker restarts. | v0.0.0-alpha.2 |
exclusive optional | boolean | Restrict queue to this connection and delete on close. | v0.0.0-alpha.2 |
autoDelete optional | boolean | Delete queue automatically when last consumer cancels. | v0.0.0-alpha.2 |
nowait optional | boolean | Do not wait for broker Queue.DeclareOk reply. | v0.0.0-alpha.2 |
arguments optional | Record<string, unknown> | Optional queue arguments (e.g., x-message-ttl, x-dead-letter-exchange). | v0.0.0-alpha.2 |
AmqpDeleteQueueOptions
Section titled “AmqpDeleteQueueOptions”export interface AmqpDeleteQueueOptions {
ifUnused?: boolean;
ifEmpty?: boolean;
nowait?: boolean;
}
Options accepted by AmqpChannel.deleteQueue().
| Property | Type | Description | Since |
|---|---|---|---|
ifUnused optional | boolean | Only delete if queue currently has no consumers. | v0.0.0-alpha.2 |
ifEmpty optional | boolean | Only delete if queue currently has zero queued messages. | v0.0.0-alpha.2 |
nowait optional | boolean | Do not wait for broker Queue.DeleteOk reply. | v0.0.0-alpha.2 |
AmqpMessageProperties
Section titled “AmqpMessageProperties”export interface AmqpMessageProperties {
contentType?: string;
contentEncoding?: string;
headers?: Record<string, unknown>;
deliveryMode?: number;
priority?: number;
correlationId?: string;
replyTo?: string;
expiration?: string;
messageId?: string;
timestamp?: number;
type?: string;
userId?: string;
appId?: string;
clusterId?: string;
}
AMQP 0-9-1 Basic properties attached to published and delivered messages.
| Property | Type | Description | Since |
|---|---|---|---|
contentType optional | string | MIME content type (e.g., "application/json"). | v0.0.0-alpha.2 |
contentEncoding optional | string | MIME content encoding (e.g., "gzip"). | v0.0.0-alpha.2 |
headers optional | Record<string, unknown> | Custom AMQP application headers table. | v0.0.0-alpha.2 |
deliveryMode optional | number | Delivery persistence mode (1 transient, 2 persistent). | v0.0.0-alpha.2 |
priority optional | number | Message priority (0..=255). | v0.0.0-alpha.2 |
correlationId optional | string | Application correlation identifier for RPC flows. | v0.0.0-alpha.2 |
replyTo optional | string | Reply queue or routing key for RPC responses. | v0.0.0-alpha.2 |
expiration optional | string | Per-message expiration string in milliseconds. | v0.0.0-alpha.2 |
messageId optional | string | Application-defined message identifier. | v0.0.0-alpha.2 |
timestamp optional | number | Unix epoch timestamp in seconds. | v0.0.0-alpha.2 |
type optional | string | Application message type name. | v0.0.0-alpha.2 |
userId optional | string | Authenticated user identifier validated by the broker. | v0.0.0-alpha.2 |
appId optional | string | Publishing application identifier. | v0.0.0-alpha.2 |
clusterId optional | string | Optional AMQP cluster ID. | v0.0.0-alpha.2 |
AmqpPublishOptions
Section titled “AmqpPublishOptions”export interface AmqpPublishOptions extends AmqpMessageProperties {
mandatory?: boolean;
immediate?: boolean;
}
Options accepted by AmqpChannel.publish().
| Property | Type | Description | Since |
|---|---|---|---|
mandatory optional | boolean | Return unroutable messages via Basic.Return. | v0.0.0-alpha.2 |
immediate optional | boolean | Require immediate consumer delivery. | v0.0.0-alpha.2 |
AmqpConsumeOptions
Section titled “AmqpConsumeOptions”export interface AmqpConsumeOptions {
consumerTag?: string;
noLocal?: boolean;
noAck?: boolean;
exclusive?: boolean;
arguments?: Record<string, unknown>;
}
Options accepted by AmqpChannel.consume().
| Property | Type | Description | Since |
|---|---|---|---|
consumerTag optional | string | Custom consumer tag (broker/client assigns one if omitted). | v0.0.0-alpha.2 |
noLocal optional | boolean | Suppress messages published on the same connection. | v0.0.0-alpha.2 |
noAck optional | boolean | Disable explicit broker acknowledgments (no-ack). | v0.0.0-alpha.2 |
exclusive optional | boolean | Request exclusive consumer access to the queue. | v0.0.0-alpha.2 |
arguments optional | Record<string, unknown> | Optional consumer field-table arguments. | v0.0.0-alpha.2 |
AmqpMessage
Section titled “AmqpMessage”export interface AmqpMessage {
readonly consumerTag?: string;
readonly deliveryTag: number | bigint;
readonly redelivered: boolean;
readonly exchange: string;
readonly routingKey: string;
readonly messageCount?: number;
readonly properties: AmqpMessageProperties;
readonly content: Uint8Array;
}
Message delivered by AmqpChannel.get() or AmqpChannel.consume().
| Property | Type | Description | Since |
|---|---|---|---|
consumerTag readonly optional | string | Consumer tag for Basic.Deliver, omitted for Basic.GetOk. | v0.0.0-alpha.2 |
deliveryTag readonly | number | bigint | Channel-scoped delivery tag passed to ack() / nack(). | v0.0.0-alpha.2 |
redelivered readonly | boolean | true if this message was previously delivered and requeued. | v0.0.0-alpha.2 |
exchange readonly | string | Exchange name through which the message was routed. | v0.0.0-alpha.2 |
routingKey readonly | string | Routing key used when publishing the message. | v0.0.0-alpha.2 |
messageCount readonly optional | number | Remaining queue depth reported on Basic.GetOk. | v0.0.0-alpha.2 |
properties readonly | AmqpMessageProperties | AMQP message properties and headers. | v0.0.0-alpha.2 |
content readonly | Uint8Array | Raw message body bytes. | v0.0.0-alpha.2 |
AmqpChannel
Section titled “AmqpChannel”export interface AmqpChannel {
declareExchange(
exchange: string,
type: "direct" | "fanout" | "topic" | "headers" | (string & {}),
options?: AmqpExchangeOptions,
): Promise<void>;
deleteExchange(exchange: string, options?: AmqpDeleteExchangeOptions): Promise<void>;
declareQueue(
queue: string,
options?: AmqpQueueOptions,
): Promise<{ queue: string; messageCount: number; consumerCount: number }>;
deleteQueue(
queue: string,
options?: AmqpDeleteQueueOptions,
): Promise<{ messageCount: number }>;
bindQueue(
queue: string,
exchange: string,
routingKey: string,
args?: Record<string, unknown>,
): Promise<void>;
publish(
exchange: string,
routingKey: string,
content: string | Uint8Array,
options?: AmqpPublishOptions,
): Promise<void>;
get(queue: string, options?: { noAck?: boolean }): Promise<AmqpMessage | null>;
consume(
queue: string,
onMessage: (message: AmqpMessage) => void | Promise<void>,
options?: AmqpConsumeOptions,
): Promise<string>;
cancel(consumerTag: string): Promise<void>;
ack(deliveryTag: number | bigint, multiple?: boolean): Promise<void>;
nack(deliveryTag: number | bigint, multiple?: boolean, requeue?: boolean): Promise<void>;
qos(prefetchCount: number, global?: boolean): Promise<void>;
close(): Promise<void>;
[Symbol.asyncDispose](): Promise<void>;
}
Multiplexed AMQP 0-9-1 channel returned by AmqpConnection.createChannel().
AmqpChannel.declareExchange
Section titled “AmqpChannel.declareExchange”declareExchange(
exchange: string,
type: "direct" | "fanout" | "topic" | "headers" | (string & {}),
options?: AmqpExchangeOptions,
): Promise<void>;
Declare or verify an exchange (Exchange.Declare).
| Name | Type | Description |
|---|---|---|
exchange | string | — |
type | "direct" | "fanout" | "topic" | "headers" | (string & {}) | — |
options optional | AmqpExchangeOptions | — |
Promise<void>AmqpChannel.deleteExchange
Section titled “AmqpChannel.deleteExchange”deleteExchange(exchange: string, options?: AmqpDeleteExchangeOptions): Promise<void>;
Delete an exchange (Exchange.Delete).
| Name | Type | Description |
|---|---|---|
exchange | string | — |
options optional | AmqpDeleteExchangeOptions | — |
Promise<void>AmqpChannel.declareQueue
Section titled “AmqpChannel.declareQueue”declareQueue(
queue: string,
options?: AmqpQueueOptions,
): Promise<{ queue: string; messageCount: number; consumerCount: number }>;
Declare or verify a queue (Queue.Declare), returning queue metadata.
| Name | Type | Description |
|---|---|---|
queue | string | — |
options optional | AmqpQueueOptions | — |
Promise<{ queue: string; messageCount: number; consumerCount: number }>AmqpChannel.deleteQueue
Section titled “AmqpChannel.deleteQueue”deleteQueue(
queue: string,
options?: AmqpDeleteQueueOptions,
): Promise<{ messageCount: number }>;
Delete a queue (Queue.Delete), returning purged message count.
| Name | Type | Description |
|---|---|---|
queue | string | — |
options optional | AmqpDeleteQueueOptions | — |
Promise<{ messageCount: number }>AmqpChannel.bindQueue
Section titled “AmqpChannel.bindQueue”bindQueue(
queue: string,
exchange: string,
routingKey: string,
args?: Record<string, unknown>,
): Promise<void>;
Bind queue to exchange using routingKey (Queue.Bind).
| Name | Type | Description |
|---|---|---|
queue | string | — |
exchange | string | — |
routingKey | string | — |
args optional | Record<string, unknown> | — |
Promise<void>AmqpChannel.publish
Section titled “AmqpChannel.publish”publish(
exchange: string,
routingKey: string,
content: string | Uint8Array,
options?: AmqpPublishOptions,
): Promise<void>;
Publish a message to exchange with routingKey (Basic.Publish).
| Name | Type | Description |
|---|---|---|
exchange | string | — |
routingKey | string | — |
content | string | Uint8Array | — |
options optional | AmqpPublishOptions | — |
Promise<void>AmqpChannel.get
Section titled “AmqpChannel.get”get(queue: string, options?: { noAck?: boolean }): Promise<AmqpMessage | null>;
Poll a single message from queue (Basic.Get), or null if empty.
| Name | Type | Description |
|---|---|---|
queue | string | — |
options optional | { noAck?: boolean } | — |
Promise<AmqpMessage | null>AmqpChannel.consume
Section titled “AmqpChannel.consume”consume(
queue: string,
onMessage: (message: AmqpMessage) => void | Promise<void>,
options?: AmqpConsumeOptions,
): Promise<string>;
Subscribe a callback consumer (Basic.Consume) and resolve with its consumer tag.
| Name | Type | Description |
|---|---|---|
queue | string | — |
onMessage | (message: AmqpMessage) => void | Promise<void> | — |
options optional | AmqpConsumeOptions | — |
Promise<string>AmqpChannel.cancel
Section titled “AmqpChannel.cancel”cancel(consumerTag: string): Promise<void>;
Cancel an active consumer (Basic.Cancel).
| Name | Type | Description |
|---|---|---|
consumerTag | string | — |
Promise<void>AmqpChannel.ack
Section titled “AmqpChannel.ack”ack(deliveryTag: number | bigint, multiple?: boolean): Promise<void>;
Acknowledge one or more deliveries (Basic.Ack).
| Name | Type | Description |
|---|---|---|
deliveryTag | number | bigint | — |
multiple optional | boolean | — |
Promise<void>AmqpChannel.nack
Section titled “AmqpChannel.nack”nack(deliveryTag: number | bigint, multiple?: boolean, requeue?: boolean): Promise<void>;
Negatively acknowledge one or more deliveries (Basic.Nack).
| Name | Type | Description |
|---|---|---|
deliveryTag | number | bigint | — |
multiple optional | boolean | — |
requeue optional | boolean | — |
Promise<void>AmqpChannel.qos
Section titled “AmqpChannel.qos”qos(prefetchCount: number, global?: boolean): Promise<void>;
Configure channel QoS prefetch count (Basic.Qos).
| Name | Type | Description |
|---|---|---|
prefetchCount | number | — |
global optional | boolean | — |
Promise<void>AmqpChannel.close
Section titled “AmqpChannel.close”close(): Promise<void>;
Close this AMQP channel. Idempotent.
Promise<void>AmqpChannel.[Symbol.asyncDispose]
Section titled “AmqpChannel.[Symbol.asyncDispose]”[Symbol.asyncDispose](): Promise<void>;
Close the channel asynchronously when disposed via await using.
Promise<void>AmqpConnection
Section titled “AmqpConnection”export interface AmqpConnection {
createChannel(): Promise<AmqpChannel>;
close(): Promise<void>;
[Symbol.asyncDispose](): Promise<void>;
}
Connected AMQP 0-9-1 broker connection returned by connect().
AmqpConnection.createChannel
Section titled “AmqpConnection.createChannel”createChannel(): Promise<AmqpChannel>;
Open a new multiplexed AmqpChannel on this connection.
AmqpConnection.close
Section titled “AmqpConnection.close”close(): Promise<void>;
Close the AMQP connection and all open channels. Idempotent.
Promise<void>AmqpConnection.[Symbol.asyncDispose]
Section titled “AmqpConnection.[Symbol.asyncDispose]”[Symbol.asyncDispose](): Promise<void>;
Close the connection asynchronously when disposed via await using.
Promise<void>Type Aliases
Section titled “Type Aliases”AmqpErrorCode
Section titled “AmqpErrorCode”export type AmqpErrorCode =
| "VAEL_AMQP_CONFIG"
| "VAEL_AMQP_CONNECT"
| "VAEL_AMQP_TLS"
| "VAEL_AMQP_AUTH"
| "VAEL_AMQP_TIMEOUT"
| "VAEL_AMQP_PROTOCOL"
| "VAEL_AMQP_SERVER"
| "VAEL_AMQP_LIMIT"
| "VAEL_AMQP_CLOSED"
| "VAEL_AMQP_IO"
| "VAEL_AMQP_NOT_FOUND";
Stable screaming-snake-case error codes reported on AmqpError.code.
