@cloudamqp/amqp-client
Version:
AMQP 0-9-1 client, both for browsers (WebSocket) and node (TCP Socket)
57 lines • 2.42 kB
TypeScript
import type { AMQPChannel } from "./amqp-channel.js";
import type { AMQPConsumer } from "./amqp-consumer.js";
import type { AMQPMessage } from "./amqp-message.js";
import type { ParserMap } from "./amqp-codec-registry.js";
/**
* A persistent queue subscription returned by {@link AMQPQueue.subscribe}.
*
* Remains valid across reconnections — the underlying channel and consumer tag
* are swapped in-place after each reconnect. Use `cancel()` to unsubscribe and
* remove from auto-recovery.
*/
export declare class AMQPSubscription {
protected consumer: AMQPConsumer;
/** The underlying channel. Reflects the most recent channel after a reconnect. */
get channel(): AMQPChannel;
/** The consumer tag. Reflects the most recent tag after a reconnect. */
get consumerTag(): string;
/**
* Cancel the subscription, close its dedicated channel, and remove it
* from session auto-recovery.
*
* The subscription owns the channel that `queue.subscribe()` opened
* for it, so cancelling here also closes that channel — otherwise
* each cancelled subscription leaks a channel until the connection
* drops.
*
* Best-effort: never throws on wire-level failures. If the channel
* dropped mid-cancel or the broker is gone, the consumer is already
* effectively dead — there's nothing for the caller to recover from,
* so swallowing the error means call sites don't need `.catch(() => {})`
* boilerplate around every cancel.
*/
cancel(): Promise<void>;
}
/**
* A persistent queue subscription that yields messages via an async iterator.
* Returned by {@link AMQPQueue.subscribe} when no callback is provided.
*
* Bridges across reconnections — the iterator continues yielding after each
* reconnect without the caller needing to re-subscribe.
*
* @example
* ```ts
* const sub = await session.subscribe("my-queue", { noAck: true })
* for await (const msg of sub) {
* console.log(msg.bodyString())
* }
* ```
*/
export declare class AMQPGeneratorSubscription<P extends ParserMap = {}> extends AMQPSubscription implements AsyncIterable<AMQPMessage<P>> {
private stopped;
private consumerReady?;
setConsumer(consumer: AMQPConsumer): void;
cancel(): Promise<void>;
[Symbol.asyncIterator](): AsyncGenerator<AMQPMessage<P>, void, undefined>;
}
//# sourceMappingURL=amqp-subscription.d.ts.map