Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@Injectable()
class SubscribeService {
nackCount = 0;
@RabbitSubscribe({
exchange,
routingKey: nackRoutingKey,
queue: nackRoutingKey,
})
shouldNack(message: object, raw: amqplib.ConsumeMessage) {
nackHandler();
return new Nack();
}
@RabbitSubscribe({
exchange,
routingKey: nackAndRequeueRoutingKey,
queue: nackAndRequeueRoutingKey,
})
async shouldNackAndRequeueTimes3(
message: object,
raw: amqplib.ConsumeMessage,
) {
++this.nackCount;
nackAndRequeueHandler();
// await sleep(15);
if (this.nackCount >= 3) {
return new Nack();
}
return new Nack(true);
}
} from '@golevelup/nestjs-rabbitmq';
import { INestApplication, Injectable } from '@nestjs/common';
import { Test } from '@nestjs/testing';
const testHandler = jest.fn();
const exchange = 'testSubscribeExhange';
const routingKey1 = 'testSubscribeRoute1';
const routingKey2 = 'testSubscribeRoute2';
const testMessage = {
messageProp: 42,
};
@Injectable()
class SubscribeService {
@RabbitSubscribe({
exchange,
routingKey: [routingKey1, routingKey2],
queue: 'subscribeQueue',
})
handleSubscribe(message: object) {
testHandler(message);
}
}
describe('Rabbit Subscribe', () => {
let app: INestApplication;
let amqpConnection: AmqpConnection;
const rabbitHost = process.env.NODE_ENV === 'ci' ? 'rabbit' : 'localhost';
const uri = `amqp://rabbitmq:rabbitmq@${rabbitHost}:5672`;
const exchange = 'testSubscribeExhange';
const nackRoutingKey = 'nackRoutingKey';
const nackAndRequeueRoutingKey = 'nackAndRequeueRoutingKey';
const testMessage = {
messageProp: 42,
};
const nackHandler = jest.fn();
const nackAndRequeueHandler = jest.fn();
@Injectable()
class SubscribeService {
nackCount = 0;
@RabbitSubscribe({
exchange,
routingKey: nackRoutingKey,
queue: nackRoutingKey,
})
shouldNack(message: object, raw: amqplib.ConsumeMessage) {
nackHandler();
return new Nack();
}
@RabbitSubscribe({
exchange,
routingKey: nackAndRequeueRoutingKey,
queue: nackAndRequeueRoutingKey,
})
async shouldNackAndRequeueTimes3(
message: object,