在哪里可以找到 SqsListener

Where can I find SqsListener

我们正在尝试使用 spring-cloud-aws 从 AWS SQS

接收消息

我们希望使用注释接收消息。在springdocumentation中,令人费解。

下面,他们声明使用 MessageMapping 和 QueueMessageHandler 注释。

Annotation-driven listener endpoints are the easiest way for listening on SQS messages. Simply annotate methods with MessageMapping and the QueueMessageHandler will route the messages to the annotated methods.

但在示例中,使用了@SQSListener。

@SqsListener("queueName")
public void queueListener(Person person) {
    // ...
}

我搜索了@SqsListener,发现它被用在测试 class 中,例如 here。所以我们尝试导入,org.springframework.cloud.aws.messaging.listener.annotation.SqsListener。不幸的是,此注释 class 在最新版本中不可用。

我用的org.springframework.cloud.aws.messaging.listener.annotation.SqsListener是正品吗?或者它还没有出现在发布的版本中?如果未发布,我可以使用 @MessageMapping 接收来自 SQS 的消息吗?

它似乎不包含在 Spring Cloud AWS 的 1.0.4 版本中,但是我在使用 1.1.0.RC1

时能够成功导入 SqsListener

您需要添加:

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-aws:1.1.0.RC1'
        mavenBom "org.springframework.boot:spring-boot-starter-parent:1.3.3.RELEASE"
    }

此外,还需要添加消息传递依赖项(我也包含了执行器):

dependencies {
    compile("org.springframework.cloud:spring-cloud-starter-aws")
    compile("org.springframework.cloud:spring-cloud-aws-messaging")
    compile("org.springframework.boot:spring-boot-starter-actuator")
}

请注意,我还没有测试它是否真的可以使用 SQS 的消息,但至少依赖关系正在解决。

现在 @SqsListener 可用于 1.1。0.RELEASE。

我正在使用 1.1.0.RELEASE,这是我的依赖项:

compile("org.springframework.boot:spring-boot-starter:1.3.5.RELEASE")
compile("org.springframework.cloud:spring-cloud-starter-aws-messaging:1.1.0.RELEASE")

我尝试了 @SqsListener 和 @MessageMapping 这两个注释都可以正常工作。 SqsListener 是 MessageMapping 注释的特例,它添加了额外的 属性 删除策略。

我猜文档必须更新,我也很困惑。