UNPKG

@cloudamqp/amqp-client

Version:

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

46 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AMQPExchange = void 0; const amqp_codec_registry_js_1 = require("./amqp-codec-registry.js"); class AMQPExchange { constructor(session, name) { this.session = session; this.name = name; } async publish(body, options = {}) { const { confirm = true, routingKey = "", mandatory = false, ...properties } = options; const defaults = {}; if (this.session.defaultContentType) defaults.contentType = this.session.defaultContentType; if (this.session.defaultContentEncoding) defaults.contentEncoding = this.session.defaultContentEncoding; const encoded = await (0, amqp_codec_registry_js_1.serializeAndEncode)(this.session.parsers ?? {}, this.session.coders ?? {}, body, properties, defaults); if (encoded.properties.deliveryMode === undefined) encoded.properties.deliveryMode = 2; if (confirm) { const ch = await this.session.getConfirmChannel(); await ch.basicPublish(this.name, routingKey, encoded.body, encoded.properties, mandatory); } else { await this.session.withOpsChannel(async (ch) => { await ch.basicPublish(this.name, routingKey, encoded.body, encoded.properties, mandatory); }); } return this; } async bind(source, routingKey = "", args = {}) { const sourceName = typeof source === "string" ? source : source.name; await this.session.withOpsChannel((ch) => ch.exchangeBind(this.name, sourceName, routingKey, args)); return this; } async unbind(source, routingKey = "", args = {}) { const sourceName = typeof source === "string" ? source : source.name; await this.session.withOpsChannel((ch) => ch.exchangeUnbind(this.name, sourceName, routingKey, args)); return this; } async delete(params) { await this.session.withOpsChannel((ch) => ch.exchangeDelete(this.name, params)); } } exports.AMQPExchange = AMQPExchange; //# sourceMappingURL=amqp-exchange.js.map