我在AWS Lambda上运行Spring Cloud Function处理SNS事件。对于某些错误情况,我想触发自动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;
}
}
我们目前不提供重试支持,但考虑到每个函数都转换为反应函数,如果你使用reactor API声明你的函数,你当然可以自己做。基本上Function<Flux<SNSEvent>, Flux<Response>>
然后你可以使用一个可用的重试操作(例如,retryBackoff
)。