nestjs-sqs
nestjs-sqs copied to clipboard
Example code
This might not be the place for this, but I'm at a loss. I'm new to NestJS and using AWS SQS queues. I can consume messages, but I can't send them. I've got an AppService pretty much identical to the readme example, but it keeps failing:
export class AppService {
public constructor(private readonly sqsService: SqsService) {}
getHello(): string {
return 'Hello World YouTube';
}
public async sendMessage(message) {
const id = String(Math.floor(Math.random() * 1000000));
await this.sqsService.send(TestQueue.Test, {
id,
body: { test: true },
groupId: 'test',
deduplicationId: id,
delaySeconds: 0,
});
}
}
When I run the app and try to send a message (through a POST call also handled by this app) I get these messages:
[Nest] 22049 - 05/27/2021, 6:27:22 PM [NestFactory] Starting Nest application...
[Nest] 22049 - 05/27/2021, 6:27:22 PM [InstanceLoader] HttpModule dependencies initialized +25ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [InstanceLoader] DiscoveryModule dependencies initialized +0ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [InstanceLoader] SqsModule dependencies initialized +0ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [RoutesResolver] AppController {}: +5ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [RouterExplorer] Mapped {, GET} route +3ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [RoutesResolver] SpaceController {/space}: +1ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [RouterExplorer] Mapped {/space, GET} route +0ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [RoutesResolver] MessagesController {/messages}: +1ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [RouterExplorer] Mapped {/messages, GET} route +0ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [RouterExplorer] Mapped {/messages, POST} route +1ms
[Nest] 22049 - 05/27/2021, 6:27:22 PM [NestApplication] Nest application successfully started +35ms
[Nest] 22049 - 05/27/2021, 6:27:26 PM [ExceptionsHandler] Failed to send messages: 742884 +4328ms
Error: Failed to send messages: 742884
at Producer.sendBatch (/Users/dougfarrell/tmp/sqs-handler/node_modules/sqs-producer/dist/producer.js:56:15)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async AppService.sendMessage (/Users/dougfarrell/tmp/sqs-handler/dist/app.service.js:25:9)
at async /Users/dougfarrell/tmp/sqs-handler/node_modules/@nestjs/core/router/router-execution-context.js:46:28
at async /Users/dougfarrell/tmp/sqs-handler/node_modules/@nestjs/core/router/router-proxy.js:9:17
Any help or suggestions would be greatly appreciated.
Thanks in advance, Doug
@Doug-Cleo, faced the same and resolved with removing deduplicationId
and groupId
fields from options. My guess is with those fields set queue type needs to be of FIFO type.