Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure custom Spring Cloud AWS SimpleMessageListenerContainerFactory so it keeps working with @SqsListener

I am trying to get SpringCloud AWS SQS working with a custom SimpleMessageListenerContainerFactory so i can set timeouts and maxnumber of messages. Without the custom SimpleMessageListenerContainerFactory methods that are annotated with the @SqsListener nicely pickup messages that are in SQS. But when i try to configure a custom SimpleMessageListenerContainerFactory the annotation stops working.

@Bean
public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory(AmazonSQSAsync amazonSqs) {
    SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
    factory.setAmazonSqs(amazonSqs);
    factory.setAutoStartup(true);
    factory.setMaxNumberOfMessages(10);
    factory.setWaitTimeOut(2000);
    return factory;
}

How can i get the normal @SqsListener behaviour when defining a custom SimpleMessageListenerContainerFactory?

@Component
public class SqsMessageConsumer {
    @SqsListener("incoming-data")
    private void doSomething(String payload) {
        System.out.println("data = " + payload);
    }
}
like image 323
Marco Avatar asked Oct 17 '16 17:10

Marco


People also ask

How many messages can be read from SQS at once?

A single Amazon SQS message queue can contain an unlimited number of messages. However, there is a quota of 120,000 for the number of inflight messages for a standard queue and 20,000 for a FIFO queue.

Can we use spring Cloud in AWS?

Spring Cloud for AWS comes into play as an integrator of AWS services. In this tutorial, we'll develop a demo application that integrates with the core services Amazon Simple Storage Service (Amazon S3) and Amazon Simple Queue Service (Amazon SQS).

What is a SQS listener?

Overview. Amazon Simple Queue Service (SQS) is a hosted message queuing service for distributing messages amongst machines. You can configure API Gateway to poll an Amazon SQS queue at a set rate. Any message found on the SQS queue in this interval can be sent to a policy for processing.

Does AWS support spring boot?

Spring Cloud AWS makes AWS a first-class citizen cloud provider for Spring Boot applications. We showed how easy it is to integrate core AWS services like SQS, S3, or the Parameter Store.


1 Answers

Not sure what you have missed but there is a test exactly for such a use-case:

@EnableSqs
@Configuration
public static class ConfigurationWithCustomContainerFactory {


    @Bean
    public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory() {
        SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
        factory.setAmazonSqs(amazonSQS());
        ...
        return factory;
    }

    @Bean
    public AmazonSQSAsync amazonSQS() {
        return AMAZON_SQS;
    }

}

So, @EnaqbleSqs is still here and SqsConfiguration is @Autowired with your custom SimpleMessageListenerContainerFactory @Bean.

like image 184
Artem Bilan Avatar answered Sep 26 '22 10:09

Artem Bilan