【问题标题】:Spring Cloud AWS SQS Listener not workingSpring Cloud AWS SQS 侦听器不起作用
【发布时间】:2018-01-31 22:11:28
【问题描述】:

每当在 Amazon S3 中上传文件时,我都会尝试为 AWS SQS 配置 Listner。我已从 S3 配置事件,以便在 S3 中上传文件时在 SQS 中转储消息。

现在我正在使用 Spring cloud(版本 - 1.2.1.RELEASE)为 S3 事件配置 SQS Listner。 以下是我的配置文件:

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 不工作。

我错过了什么吗?

【问题讨论】:

    标签: java spring amazon-web-services spring-boot amazon-s3


    【解决方案1】:

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

    如果不是这种情况,请确保 SimpleMessageListenerContainer's 自动启动未设置为 false。

    【讨论】:

      猜你喜欢
      • 2019-08-05
      • 1970-01-01
      • 2017-06-13
      • 1970-01-01
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      相关资源
      最近更新 更多