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);
}
}
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.
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).
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With