Reputation: 1031
I am trying to configure a Listner for AWS SQS whenever a file is uploaded in Amazon S3. I have configured the event from S3 so that a message is dumped in the SQS when a file is uploaded in S3.
Now I am using Spring cloud(version - 1.2.1.RELEASE) to configure a SQS Listner for the S3 event. Below are my config files :
aws-config.xml
<aws-context:context-credentials>
<aws-context:simple-credentials access-key="*******" secret-key="******"/>
</aws-context:context-credentials>
<aws-context:context-region region="ap-south-1" />
<aws-context:context-resource-loader/>
<aws-messaging:annotation-driven-queue-listener max-number-of-messages="10"
wait-time-out="20" visibility-timeout="3600""/>
AwsResourceConfig.java
@Configuration
@EnableSqs
@ImportResource("classpath:/aws-config.xml")
@EnableRdsInstance(databaseName = "******",
dbInstanceIdentifier = "*****",
password = "******")
public class AwsResourceConfig {
@SqsListener(value = "souviksqs", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void receiveNewFileUpload(S3EventNotification event) {
try {
if ( event != null && !CollectionUtils.isNullOrEmpty( event.getRecords() ) && event.getRecords().get( 0 ) != null ) {
S3Entity entry = event.getRecords().get(0).getS3();
System.out.println("############ File Uploaded to ###################### " + entry.getBucket().getName() + "/" + entry.getObject().getKey());
}
} catch (Exception e) {
System.out.println("Error reading the SQS message " + e);
}
}
}
Whenever there is a file uploaded in S3,a message is added in SQS. But the SQSListener is not working.
Am I missing something?
Upvotes: 4
Views: 7281
Reputation: 97
I have face this issue and found out that it was a versioning problem.
Spring Boot 3.0x requires Spring Cloud AWS 3.0x and AWS Java SDK 2.x
Click here to get detailed info on Spring Cloud and AWS Compatability versions
In order to create a Consumer in Spring Boot 3.0, you need to use @EnableScheduling Bean in your main application. Then you need to use @Scheduled(fixedDelay = 3000) above the receive method. @Scheduled bean replaces the @SqsListener here. You can visit this link for more info.
Upvotes: 0
Reputation: 3677
Make sure you are using spring-cloud-aws-messaging
and not spring-cloud-starter-aws-messaging
.
Also if that isn't the case, make sure SimpleMessageListenerContainer's
auto startup is not set to false.
Upvotes: 5