2

我无法使用 SQS 消息触发器使基于 Spring-Cloud 的 AWS Lambda 函数工作。我正在使用 Spring Cloud Function AWS 适配器版本 2.0.1.RELEASE 并尝试部署到 AWS EU-WEST-2 区域。

我的 SpringBootRequestHandler 定义如下:

    import org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler;

    import com.amazonaws.services.lambda.runtime.events.SQSEvent;
    public class ReplicationHandler extends SpringBootRequestHandler<SQSEvent, String>{

}

我的@Bean 函数如下所示:

    @Bean
    public Function<SQSEvent, String> handleEvent() {   
        return value -> processEvent((SQSEvent)value);
    }

我用以下测试事件来提供它:

{
  "Records": [
    {
      "messageId": "02a4e04b-a1d2-417a-b073-56123be35ac6",
      "receiptHandle": "AQEB0fsSc76vU9Y6vQEz",
      "body": "hello world",
      "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "1553860061037",
        "SenderId": "AIDAIVEA3AGEU7NF6DRAG",
        "ApproximateFirstReceiveTimestamp": "1553860061042"
      },
      "messageAttributes": {},
      "md5OfBody": "a4d19d8b1019e01bb875eea6232bf2f1",
      "eventSource": "aws:sqs",
      "eventSourceARN": "arn:aws:sqs:eu-west-2:XXXXX:YYYYY",
      "awsRegion": "eu-west-2"
    }
  ]
}


当我运行这个时,我收到以下错误:

{
  "errorMessage": "reactor.core.publisher.FluxJust cannot be cast to com.amazonaws.services.lambda.runtime.events.SQSEvent",
  "errorType": "java.lang.ClassCastException",
  "stackTrace": [
    "org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.apply(SpringFunctionInitializer.java:132)",
    "org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler.handleRequest(SpringBootRequestHandler.java:48)"
  ]
}

有人对这里出了什么问题有任何建议吗?或者,如果网络上有任何适用于我的确切场景的工作示例,那也很好。

4

0 回答 0