Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeadLetterQueueSourceArn missing while receiving message from DLQ #921

Open
jgchoppe opened this issue Nov 28, 2023 · 5 comments · Fixed by #985
Open

DeadLetterQueueSourceArn missing while receiving message from DLQ #921

jgchoppe opened this issue Nov 28, 2023 · 5 comments · Fixed by #985

Comments

@jgchoppe
Copy link

Hey!

I'm currently using your awesome tool to test AWS SQS queues locally.
The goal of my architecture would be to have SQS queues with a DeadLetters Queue.
I'm able to pull messages from the DLQ, However DeadLetterQueueSourceArn is missing from the attributes.

Example with AWS SQS:

{
    "Messages": [
        {
            "MessageId": "************************************",
            "ReceiptHandle": "*****",
            "MD5OfBody": "*****",
            "Body": "example",
            "Attributes": {
                "SenderId": "*********************",
                "ApproximateFirstReceiveTimestamp": "1701176294398",
                "ApproximateReceiveCount": "8",
                "SentTimestamp": "1701176278493",
                "SequenceNumber": "18882245240547823616",
                "MessageDeduplicationId": "************************************",
                "MessageGroupId": "test",
                "DeadLetterQueueSourceArn": "arn:aws:sqs:us-west-2:*****:example.fifo"
            }
        }
    ]
}

Example with ElasticMQ:

{
    "Messages": [
        {
            "MessageId": "************************************",
            "ReceiptHandle": "************************************#************************************",
            "MD5OfBody": "e4b3b7558956e56fcb6b5397bdc6523d",
            "Body": "example",
            "Attributes": {
                "ApproximateFirstReceiveTimestamp": "1701176081533",
                "SentTimestamp": "1701175918154",
                "MessageDeduplicationId": "************************************",
                "SenderId": "*********",
                "ApproximateReceiveCount": "6",
                "MessageGroupId": "test",
                "SequenceNumber": "0"
            }
        }
    ]
}

It would be great if this attribute could be added when the message is moved to the DLQ.

@jgchoppe jgchoppe changed the title DeadLetterQueueSourceArn missing in attributes while receiving message DeadLetterQueueSourceArn missing in attributes while receiving message from DLQ Nov 28, 2023
@jgchoppe jgchoppe changed the title DeadLetterQueueSourceArn missing in attributes while receiving message from DLQ DeadLetterQueueSourceArn missing while receiving message from DLQ Nov 28, 2023
@micossow
Copy link
Contributor

micossow commented Apr 3, 2024

Fixed in v1.5.8
Thanks for reporting the issue!

@sergij
Copy link
Contributor

sergij commented Jan 2, 2025

Hi!

It seems that the fix provided in #985 is not completely accurate, as according to AWS SQS specifications attribute DeadLetterQueueSourceArn should be provided with the message that is retrieved from the dead letter queue after it was forwarded there from the source queue, and the meaning of this attribute is to provide link to the original queue where the message was sent to, not where the message should go after exhausting maxReceiveCount attempts.

Looking at #985, test to be passed should look something like:

  test("should return DeadLetterQueueSourceArn in receive DLQ message attributes") {
    // given
    val messageBody = "Message 1"
    val createDlqQueueResult = client.createQueue(new CreateQueueRequest("testDlq")).getQueueUrl
    val redrivePolicy = RedrivePolicy("testDlq", awsRegion, awsAccountId, 1).toJson.toString

    val createQueueResult = client
      .createQueue(
        new CreateQueueRequest("main")
          .withAttributes(
            Map(redrivePolicyAttribute -> redrivePolicy).asJava
          )
      )
      .getQueueUrl

    // when
    client.sendMessage(createQueueResult, messageBody)
    // all we need to achieve here is to trigger move message to dead letter queue
    client.receiveMessage(
      new ReceiveMessageRequest()
        .withQueueUrl(createQueueResult)
        .withAttributeNames("All")
    )
    // data we are looking for should be coming with a message received from DLQ
    val receiveDlqResult = client.receiveMessage(
      new ReceiveMessageRequest()
        .withQueueUrl(createDlqQueueResult)
        .withAttributeNames("All")
    )

    // then
    receiveDlqResult.getMessages.asScala.toList.flatMap(_.getAttributes.asScala.toList) should contain(
      ("DeadLetterQueueSourceArn", s"arn:aws:sqs:$awsRegion:$awsAccountId:main")
    )
  }

@micossow
Copy link
Contributor

micossow commented Jan 3, 2025

I'll check this

@micossow micossow reopened this Jan 3, 2025
@sergij
Copy link
Contributor

sergij commented Jan 3, 2025

Thank you @micossow! Just for reference I prepared this change set: #1086

It is not very clean as it makes messageSystemAttributes mutable in order to store "sourceQueue" metadata, but on high level it achieves what is required.

@micossow
Copy link
Contributor

micossow commented Jan 6, 2025

Released in v1.6.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants