UNPKG

onirii

Version:

Universal queue SDK

41 lines (40 loc) 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AmqpOriginalConsumerWrapper = void 0; const tslib_1 = require("tslib"); /** * Amqp Original Consumer Wrapper */ class AmqpOriginalConsumerWrapper { /** * Constructor * * @param {string} consumerName consumer identify * @param {AmqpChannelService} parentService parent channel service * @param {string} queue target queue * @param {(msg: (ConsumeMessage | null)) => void} processor message processor * @param {Options.Consume} options message receive option */ constructor(consumerName, parentService, queue, processor, options) { this.consumerName = consumerName; this.parentService = parentService; this.parentService.logger.info(`Creating Consumer ${this.consumerName}`); const currentOptions = Object.assign({ consumerTag: consumerName }, options); this.parentService.currentChannelInstance.consume(queue, processor, currentOptions).catch(err => { this.parentService.logger.error(`Can't Create Consumer ${this.consumerName} Error: ${err.stack}`); throw err; }); } /** * kill this consumer * * @return {Promise<void>} -- */ kill() { return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { yield this.parentService.currentChannelInstance.cancel(this.consumerName); this.parentService.logger.warn(`Killed Consumer ${this.consumerName}`); }); } } exports.AmqpOriginalConsumerWrapper = AmqpOriginalConsumerWrapper;