How are we supposed to set up the @SQSListener deletion policy with Spring Cloud AWS 3.0.2?

1.6k Views Asked by At

The only way I've been able to figure out how to set this up is with the following override in my configuration:

@Bean("myFactory")
@ConditionalOnClass(SqsAsyncClient.class)
SqsMessageListenerContainerFactory<Object> mySqsListenerContainerFactory(
    SqsAsyncClient sqsAsyncClient) {
  return SqsMessageListenerContainerFactory.builder()
      .configure(
          options ->
              options.acknowledgementMode(
                  AcknowledgementMode.valueOf("ON_SUCCESS")))
      .sqsAsyncClient(sqsAsyncClient)
      .build();
}

And this in my @SQSListener:

@SqsListener(
      value = "myQueue",
      factory = "myFactory")

I haven't figured out how to configure this so that the io.awspring.cloud.autoconfigure.sqs.SqsAutoConfiguration class can set the acknowledgement mode and I can get the benefit of letting Spring autoconfigure everything for me that I need. Can anyone advise me on how this should be set up moving forward?

Prior to Spring Cloud AWS 3.x, we set up the @SQSListener as follows, which is no longer supported it seems:

@SqsListener(
      value = "myQueue",
      deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)

1

There are 1 best solutions below

0
seb On BEST ANSWER

In Spring Cloud AWS 3.0, the default acknowledgement mode is ON_SUCCESS [0].

Using another acknowledgement mode can currently only be done via the factory, but with the next version (3.1), it will be possible again to set it directly in the @SqsListener annotation [1].

[0] https://docs.awspring.io/spring-cloud-aws/docs/3.0.2/reference/html/index.html#sqscontaineroptions-descriptions

[1] https://github.com/awspring/spring-cloud-aws/pull/870