简体   繁体   中英

Spring Cloud AWS SQS Listener not working

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM