Spring Cloud AWS SQS监听器无法工作

4
我正在尝试配置一个监听器,以便在Amazon S3中上传文件时,为AWS SQS进行配置。我已经从S3配置了事件,因此当在S3中上传文件时,消息会被转储在SQS中。
现在我正在使用Spring Cloud(版本-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无法正常工作。

我漏掉了什么吗?

2个回答

5

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

另外,如果不是这种情况,请确保 SimpleMessageListenerContainer 的自动启动没有设置为 false。


0

我曾遇到这个问题,并发现这是一个版本问题。
Spring Boot 3.0x需要使用Spring Cloud AWS 3.0x和AWS Java SDK 2.x。

点击此处获取有关Spring Cloud和AWS兼容性版本的详细信息

要在Spring Boot 3.0中创建一个消费者,您需要在主应用程序中使用@EnableScheduling Bean。然后,在接收方法上方使用@Scheduled(fixedDelay = 3000)。@Scheduled bean将在此处替换@SqsListener。您可以访问链接以获取更多信息。


1
为什么不使用Spring Cloud AWS 3.0?我们已经处于RC阶段,GA版本应该在几周内发布。 - Tomaz Fernandes
使用EnableScheduling是一种不同的模式。它将每fixedDelay秒调用一次。 - Phan Kieu Hung

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接