@goparrot/pubsub-event-bus
Version:
NestJS EventBus extension for RabbitMQ PubSub
40 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlwaysAckStrategy = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@nestjs/common");
const interface_1 = require("../../interface");
const AbstractHandleWrapperStrategy_1 = require("./AbstractHandleWrapperStrategy");
let AlwaysAckStrategy = class AlwaysAckStrategy extends AbstractHandleWrapperStrategy_1.AbstractHandleWrapperStrategy {
constructor() {
super(...arguments);
this.strategy = interface_1.AutoAckEnum.ALWAYS_ACK;
}
addAlwaysPositiveAck(handlerWrapper, channelWrapper) {
const { handler } = handlerWrapper;
const originalMethod = handler.prototype.handle;
Reflect.defineProperty(handler.prototype, 'handle', {
...Reflect.getOwnPropertyDescriptor(handler.prototype, 'handle'),
async value(event) {
try {
await originalMethod.apply(this, [event]);
}
finally {
const message = event.message();
if (message) {
channelWrapper.ack(message);
}
}
},
});
}
process(handlerWrapper, channelWrapper) {
this.mockAckAndNack(handlerWrapper);
this.addAlwaysPositiveAck(handlerWrapper, channelWrapper);
}
};
exports.AlwaysAckStrategy = AlwaysAckStrategy;
exports.AlwaysAckStrategy = AlwaysAckStrategy = tslib_1.__decorate([
(0, common_1.Injectable)()
], AlwaysAckStrategy);
//# sourceMappingURL=AlwaysAckStrategy.js.map