UNPKG

@cloudamqp/amqp-client

Version:

AMQP 0-9-1 client, both for browsers (WebSocket) and node (TCP Socket)

64 lines 2.99 kB
import type { AMQPProperties } from "./amqp-properties.js"; import type { ResolveBody } from "./amqp-publisher.js"; import type { ParserMap, CoderMap } from "./amqp-codec-registry.js"; /** Options for {@link AMQPExchange#publish}. */ export type ExchangePublishOptions<O extends string = string> = Omit<AMQPProperties, "contentType"> & { /** Routing key. Defaults to `""`. */ routingKey?: string; /** Wait for broker confirmation. Defaults to `true`. */ confirm?: boolean; /** * Ask the broker to return the message if it can't be routed to a queue. * Returned messages are delivered to the session-level `onreturn` handler * when one is configured; otherwise the default channel handler just * logs them. Defaults to `false`. */ mandatory?: boolean; contentType?: O; }; /** * Session-level exchange handle returned by {@link AMQPSession#exchange} and its * convenience variants ({@link AMQPSession#directExchange}, etc.). * * All operations are reconnect-safe: they acquire a session channel on each * call. `publish` waits for a broker confirm; pass `{ confirm: false }` to skip the wait. */ export declare class AMQPExchange<P extends ParserMap = {}, C extends CoderMap = {}, KP extends keyof P & string = never, KC extends keyof C & string = never> { /** Exchange name. */ readonly name: string; private readonly session; /** * Publish a message to this exchange. * * When the session has parsers configured, `body` can be any value accepted * by the matching parser's `serialize` method. Without parsers, `body` must * be a string, Buffer, Uint8Array, or null. * * Defaults: `confirm: true`, `deliveryMode: 2` (persistent). Pass * `deliveryMode: 1` to send a transient message. * * @param options - routing key, publish properties; set `confirm: false` to skip broker confirmation * @returns `this` for chaining */ publish<O extends keyof P & string = KP>(body: ResolveBody<P, O>, options?: ExchangePublishOptions<O>): Promise<AMQPExchange<P, C, KP, KC>>; /** * Bind this exchange to a source exchange. * @param source - name or {@link AMQPExchange} to bind from * @returns `this` for chaining */ bind(source: string | AMQPExchange<P, C, KP, KC>, routingKey?: string, args?: Record<string, unknown>): Promise<AMQPExchange<P, C, KP, KC>>; /** * Remove a binding between this exchange and a source exchange. * @param source - name or {@link AMQPExchange} to unbind from * @returns `this` for chaining */ unbind(source: string | AMQPExchange<P, C, KP, KC>, routingKey?: string, args?: Record<string, unknown>): Promise<AMQPExchange<P, C, KP, KC>>; /** * Delete this exchange. * @param [params.ifUnused=false] - only delete if the exchange has no bindings */ delete(params?: { ifUnused?: boolean; }): Promise<void>; } //# sourceMappingURL=amqp-exchange.d.ts.map