@goparrot/pubsub-event-bus
Version:
NestJS EventBus extension for RabbitMQ PubSub
42 lines • 1.57 kB
JavaScript
import { __decorate } from "tslib";
import { Injectable } from '@nestjs/common';
import { AutoAckEnum } from '../../interface';
import { AbstractHandleWrapperStrategy } from './AbstractHandleWrapperStrategy';
let AckAndNackStrategy = class AckAndNackStrategy extends AbstractHandleWrapperStrategy {
constructor() {
super(...arguments);
this.strategy = AutoAckEnum.ACK_AND_NACK;
}
addAutoAck(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]);
const message = event.message();
if (message) {
channelWrapper.ack(message);
}
}
catch (e) {
const message = event.message();
if (message) {
channelWrapper.nack(message);
}
throw e;
}
},
});
}
process(handlerWrapper, channelWrapper) {
this.mockAckAndNack(handlerWrapper);
this.addAutoAck(handlerWrapper, channelWrapper);
}
};
AckAndNackStrategy = __decorate([
Injectable()
], AckAndNackStrategy);
export { AckAndNackStrategy };
//# sourceMappingURL=AckAndNackStrategy.js.map