1
votes

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?

1

1 Answers

0
votes

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?