【问题标题】:Where can I find SqsListener我在哪里可以找到 SqsListener
【发布时间】:2016-07-02 10:26:39
【问题描述】:

我们正在尝试使用spring-cloud-aws 来接收来自 AWS SQS 的消息

我们希望使用注释接收消息。在春天documentation,这是令人困惑的。

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

注解驱动的监听器端点是最简单的监听方式 在 SQS 消息上。只需使用 MessageMapping 和 QueueMessageHandler 会将消息路由到带注释的方法。

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

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

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

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

【问题讨论】:

  • @Alian - 你对此有什么线索吗?

标签: spring amazon-web-services spring-cloud amazon-sqs


【解决方案1】:

它似乎不包含在 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 的消息,但至少依赖关系正在解决。

【讨论】:

    【解决方案2】:

    现在@SqsListener 在 1.1.0.RELEASE 中可用。

    【讨论】:

      【解决方案3】:

      我使用的是 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 注释的一种特殊化,它添加了一个附加属性,即删除策略。

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

      【讨论】:

        猜你喜欢
        • 2014-07-16
        • 2012-05-30
        • 2013-07-13
        • 2012-06-05
        • 2011-04-24
        • 2021-02-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多