Search code examples
node.jsamazon-web-servicesamazon-sqs

AWS SQL SendMessageBatch Giving Duplicates


I have a "standard" (not FIFO) AWS SQS queue and a NodeJS app to push messages to it.

I've put a breakpoint on the app and can see values for members of the "params" parameter into the sendMessageBatch function:

clip1

After purging the queue and executing the send, I see the following in the VS Code console:

Batch send results: {
  ResponseMetadata: { RequestId: '7d892234-cd9a-5052-9bad-784682dca7e8' },
  Successful: [
    {
      Id: '0',
      MessageId: '608616c2-c19a-41c0-b113-7e8e351e84a7',
      MD5OfMessageBody: 'f7f0c2902306b87690c26e9a753721a8'
    },
    {
      Id: '1',
      MessageId: 'cc433302-fb8a-4bf8-8a6d-75e457a07e73',
      MD5OfMessageBody: '686f5605f13ba466800c2d1b092e2d63'
    },
    {
      Id: '2',
      MessageId: '4e3f960e-14a0-4811-bf2f-1c34d3063b82',
      MD5OfMessageBody: '860327ef8bc9cdb36131d7b39138ff21'
    }
  ],
  Failed: []
}

That all looks good but when I then check the queue I see two copies of each message, a total of six messages. Anyone know how to fix please?


Solution

  • I needed to intercept the request to SQS in order to diagnose this. I couldn't get Fiddler to pick them up but I discovered a tool called Http Toolkit that worked for me.

    With the intercept working, I was able to see that I was actually sending duplicate requests - because I'd failed to clear an array in a loop.