Problems using the @ssut/nestjs-sqs npm library

Viewed 1886

I'm trying to use the @ssut/nestjs-sqs library to communicate to AWS SQS queues from a Node/NestJS application. 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 example in the repository READEM, 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

How can I resolve this error?

1 Answers

I resolved this myself by debugging into the send message code and getting the AWS error code. The problem is the example code shown for the ssut@nestjs-sqs module to send a message is for an FIFO queue. If you're using a standard queue the queueuId and deduplicationId values in the message will cause the error. Remove those and it worked fine.

Related