@goparrot/pubsub-event-bus
Version:
NestJS EventBus extension for RabbitMQ PubSub
37 lines • 1.39 kB
JavaScript
import { __decorate } from "tslib";
import { Injectable } from '@nestjs/common';
import { AutoAckEnum } from '../../interface';
import { AbstractHandleWrapperStrategy } from './AbstractHandleWrapperStrategy';
let AlwaysAckStrategy = class AlwaysAckStrategy extends AbstractHandleWrapperStrategy {
constructor() {
super(...arguments);
this.strategy = 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);
}
};
AlwaysAckStrategy = __decorate([
Injectable()
], AlwaysAckStrategy);
export { AlwaysAckStrategy };
//# sourceMappingURL=AlwaysAckStrategy.js.map