簡體   English   中英

Spring Cloud AWS SQS 偵聽器不起作用

[英]Spring Cloud AWS SQS Listener not working

每當在 Amazon S3 中上傳文件時,我都會嘗試為 AWS SQS 配置 Listner。 我已經從 S3 配置了事件,以便在 S3 中上傳文件時將消息轉儲到 SQS 中。

現在我正在使用 Spring cloud(version - 1.2.1.RELEASE) 為 S3 事件配置一個 SQS 監聽器。 以下是我的配置文件:

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);

    }
}

}

每當在 S3 中上傳文件時,都會在 SQS 中添加一條消息。 但是 SQSListener 不起作用。

我錯過了什么嗎?

確保您使用的是spring-cloud-aws-messaging而不是spring-cloud-starter-aws-messaging

此外,如果情況並非如此,請確保SimpleMessageListenerContainer's自動啟動未設置為 false。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM