1

我在处理 SNS 事件的 AWS Lambda 上运行了一个 Spring Cloud 函数。对于某些错误情况,我想触发自动 Lambda 重试或触发 SNS 服务的重试功能。SNS 重试策略采用默认配置。

我尝试返回带有 {"statusCode":500} 的 JSON,当我们在 aws 控制台中进行测试调用时,它正在工作。无论如何,当我们发送此状态时,不会触发函数的重试调用。

我们使用 SpringBootRequestHandler

public class CustomerUpdatePersonHandler extends SpringBootRequestHandler<SNSEvent, Response> {

}

@Component
public class CustomerUpdatePerson implements Function<SNSEvent, Response> {

    @Override
    public Response apply(final SNSEvent snsEvent) {
       //when something goes wrong return 500 and trigger a retry
       return new Response(500)
    }
}

public class Response{
    private int statusCode;

    public Response(int code){
        this.statusCode = code;
    }

    public int getStatusCode(){
        retrun statusCode;
    }
}
4

1 回答 1

0

我们目前不提供对重试的支持,但是考虑到每个函数都被转换为反应函数,如果你使用反应器 API 声明你的函数,你当然可以自己做。基本上Function<Flux<SNSEvent>, Flux<Response>>,然后您可以使用可用的重试操作之一(例如,retryBackoff)。

于 2019-04-29T16:04:21.083 回答