UNPKG

@amirmarmul/waba-common

Version:

![GitHub release](https://img.shields.io/github/v/release/amirmarmul/waba-common?style=flat-square)

43 lines (42 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Event = void 0; const core_1 = require("../../../core"); const Connection_1 = require("./Connection"); const ChannelEvent_1 = require("./ChannelEvent"); class Event { connection; channel; priority; payload; constructor(payload) { this.connection = Connection_1.Connection.getConnection("publisher"); this.payload = payload; this.priority = 0; } init() { this.channel = ChannelEvent_1.ChannelEvent.getChannel("publisher"); this.channel.addSetup(this.setup.bind(this)); return this; } setup(channel) { channel.assertExchange(this.exchange, "topic", { durable: false }); } async publish(options = {}) { core_1.logger.debug("Publish message %s", this.constructor.name); const result = await this.channel.publish(this.exchange, this.topic, this.payload, Object.assign({ deliveryMode: 2, persistent: true, }, options)); return result; } async publishWithoutPersistence(options = {}) { core_1.logger.debug("Publish message %s", this.constructor.name); const result = await this.channel.publish(this.exchange, this.topic, this.payload, Object.assign({ deliveryMode: 1, persistent: false, }, options)); return result; } } exports.Event = Event;