Closed warubert closed 10 months ago
Solved, i was implementing the dynamic module in a wrong way, here is the right way of doing that:
import { SqsModule } from '@ssut/nestjs-sqs';
import { QueueHandler } from './queue-handler';
import { SQSClient } from '@aws-sdk/client-sqs';
import { ConfigModule } from '../config/config.module';
import { ConfigService } from '../config/config.service';
import { DevicesModule } from '../devices/devices.module';
import { forwardRef, DynamicModule, Module } from '@nestjs/common';
import { SqsMessageProducer } from './sqs-message-producer.service';
@Module({
imports: [ConfigModule, forwardRef(() => DevicesModule)],
providers: [QueueHandler, SqsMessageProducer],
exports: [QueueHandler, SqsMessageProducer],
})
export class SqsQueueModule {
static register({ queueNames }: { queueNames: string[] }): DynamicModule {
return SqsModule.registerAsync({
useFactory: function(configService: ConfigService) {
const sqs = new SQSClient({
region: configService.get('SQS_AWS_REGION'),
credentials: {
accessKeyId: configService.get('SQS_AWS_ACCESS_KEY_ID'),
secretAccessKey: configService.get('SQS_AWS_SECRET_ACCESS_KEY'),
},
})
let consumers = [];
let producers = [];
const sqsQueueUrl = configService.get('SQS_QUEUE_URL');
const sqsRegion = configService.get('SQS_AWS_REGION');
for (const queueName of queueNames) {
const queueData = {
name: queueName,
queueUrl: sqsQueueUrl + queueName,
region: sqsRegion,
sqs
};
consumers.push(queueData);
producers.push(queueData);
}
return { consumers, producers };
},
inject: [ConfigService],
});
}
}
registering:
SqsQueueModule.register(
{
queueNames: [
DEVICE_DATA_QUEUE,
TESTE_QUEUE,
RESET_DEVICE_CALIBRATION_QUEUE,
UPDATE_DEVICE_CALIBRATION_QUEUE,
DEVICE_LOG_WIPE_QUEUE
]
}),
Hello! I am trying to use a dynamic module to consume and produce message for 5 sqs queues Here is my module:
and Im registering it like this:
What happens is that only the first queue registered this way works and the others doesnt work at all (but somehow all console.logs are show when creating all queues). Someone knows how I could fix that?