简体   繁体   中英

SQS all message goes to dead letter queue

I've configured an SQS queue and an additional dead letter queue using terraform.

resource "aws_sqs_queue" "sqs_deadletter" {
  name = "worker-dead-letter"
}

resource "aws_sqs_queue" "sqs" {
  name = "worker"
/* TODO: If I enable this all messages goes to the dead letter queue
  redrive_policy = jsonencode({
    deadLetterTargetArn = aws_sqs_queue.sqs_deadletter.arn
    maxReceiveCount = 4
  })
*/
}

resource "aws_lambda_event_source_mapping" "sqs" {
  event_source_arn = aws_sqs_queue.sqs.arn
  function_name = aws_lambda_function.worker.arn
  enabled = true
  batch_size = var.batch_size
}

I use the below handler to process my messages.

@Introspected
class LegacyToModernRequestHandler : MicronautRequestHandler<SQSEvent, Unit>() {
    private val logger = KotlinLogging.logger {}

    override fun execute(input: SQSEvent) {
        input.records.forEach {
            handle(it)
        }
    }

    private fun handle(message: SQSMessage) {
        val key = message.body
        logger.info { "LegacyToModernRequestHandler($key)" }
    }
}

But all my messages goes to the DLQ. How can I indicate successful handling so that doesn't happen?

If you are not using AUTO_ACKNOWLEDGEMENT mode, you will have to explicitly acknowledge the message so that it is processed successfully. Otherwise it will go to DLQ. Can you show how have you configured your SQS queue?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM