How to configure custom Spring Cloud AWS SimpleMessageListenerContainerFactory so it keeps working with @SqsListener
amazon-sqs, spring-boot, spring-cloud
Solution
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`.
Problem
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); } } ```