gpt4 book ai didi

java - Spring Cloud AWS SQS 监听器不工作

转载 作者:行者123 更新时间:2023-12-05 02:18:17 28 4
gpt4 key购买 nike

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

我错过了什么吗?

最佳答案

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

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

关于java - Spring Cloud AWS SQS 监听器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45837702/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com