Spring-Retry

Spring Retry @Recover passing parameters

早过忘川 提交于 2019-12-05 11:01:31
I couldn't find any info about a possibility of action I need. I am using @Retryable annotation with @Recover handler method. Smth like this: @Retryable(value = {Exception.class}, maxAttempts = 5, backoff = @Backoff(delay = 10000)) public void update(Integer id) { execute(id); } @Recover public void recover(Exception ex) { logger.error("Error when updating object with id {}", id); } The problem is that I don't know, how to pass my parameter "id" to recover() method. Any ideas? Thanks in advance. According to the Spring Retry documentation , just align the parameters between the @Retryable and

Feign client and Spring retry

[亡魂溺海] 提交于 2019-12-05 04:42:05
I have a restful service calling an external service using Spring Cloud Feign client @FeignClient(name = "external-service", configuration = FeignClientConfig.class) public interface ServiceClient { @RequestMapping(value = "/test/payments", method = RequestMethod.POST) public void addPayment(@Valid @RequestBody AddPaymentRequest addPaymentRequest); @RequestMapping(value = "/test/payments/{paymentId}", method = RequestMethod.PUT) public ChangePaymentStatusResponse updatePaymentStatus(@PathVariable("paymentId") String paymentId, @Valid @RequestBody PaymentStatusUpdateRequest

Spring batch: Retry job if does not complete in particular time

孤人 提交于 2019-12-05 01:09:56
问题 I am working on a Spring batch application where I have used RetryTemplate with SimpleRetryPolicy . In this application, ItemProcessor usually takes 30-35 mins to complete a particular task. But sometimes, it takes from than 2hrs to complete that same task. Is there a way to retry my ItemProcessor , if the assigned task is not completed within given time period? I am looking for some Java/Spring in-build functionality instead of writing my own timeout logic. 回答1: You can define transactional

Spring-retry使用指南

半城伤御伤魂 提交于 2019-12-05 00:50:43
Spring-retry 该项目为Spring应用程序提供声明式重试支持,它用于Spring Batch、Spring Integration、Apache Hadoop的Spring(以及其他),命令式重试也支持显式使用。 入门 声明式示例 @Configuration @EnableRetry public class Application { @Bean public Service service() { return new Service(); } } @Service class Service { @Retryable(RemoteAccessException.class) public void service() { // ... do something } @Recover public void recover(RemoteAccessException e) { // ... panic } } 调用 service 方法,如果它由于 RemoteAccessException 失败,那么它将重试(默认情况下最多三次),如果继续失败,则执行 recover 方法, @Retryable 注解属性中有各种选项,用于包含和排除异常类型、限制重试次数和回退策略。 使用上面显示的 @Retryable

重试组件

丶灬走出姿态 提交于 2019-12-04 21:51:22
系列说明 Java retry 的一步步实现机制。 https://github.com/houbb/retry 情景导入 简单的需求 产品经理:实现一个按条件,查询用户信息的服务。 小明:好的。没问题。 代码 UserService.java public interface UserService { /** * 根据条件查询用户信息 * @param condition 条件 * @return User 信息 */ User queryUser(QueryUserCondition condition); } UserServiceImpl.java public class UserServiceImpl implements UserService { private OutService outService; public UserServiceImpl(OutService outService) { this.outService = outService; } @Override public User queryUser(QueryUserCondition condition) { outService.remoteCall(); return new User(); } } 谈话 项目经理:这个服务有时候会失败,你看下。 小明: OutService

How can I make spring @retryable configurable?

随声附和 提交于 2019-12-04 17:37:56
问题 I have this piece of code @Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class, exclude = URISyntaxException.class, backoff = @Backoff(delay = 1000, multiplier = 2) ) public void testThatService(String serviceAccountId) throws ServiceUnavailableException, URISyntaxException { //some implementation here } Is there a way I can make the maxAttempts , delay and multiplier configurable using @Value? Or is there any other approach to make such fields inside

Spring AMQP StatefulRetryOperationsInterceptor not used

我的梦境 提交于 2019-12-04 09:34:01
I am trying configure spring amqp to only retry a message a defined amount of times. Currently a message that fails e.g. because of a DataIntegrityViolationException is redelivered indefinitely. According to the documentation here I came up with the following configuration @Bean public StatefulRetryOperationsInterceptor statefulRetryOperationsInterceptor() { return RetryInterceptorBuilder.stateful() .backOffOptions(1000, 2.0, 10000) // initialInterval, multiplier, maxInterval .maxAttempts(3) .messageKeyGenerator(message -> UUID.randomUUID().toString()) .build(); } This does not seem to be

Spring batch: Retry job if does not complete in particular time

穿精又带淫゛_ 提交于 2019-12-03 16:26:53
I am working on a Spring batch application where I have used RetryTemplate with SimpleRetryPolicy . In this application, ItemProcessor usually takes 30-35 mins to complete a particular task. But sometimes, it takes from than 2hrs to complete that same task. Is there a way to retry my ItemProcessor , if the assigned task is not completed within given time period? I am looking for some Java/Spring in-build functionality instead of writing my own timeout logic. You can define transactional-attributes to a given step. ( https://docs.spring.io/spring-batch/trunk/reference/htmlsingle/

How can I make spring @retryable configurable?

*爱你&永不变心* 提交于 2019-12-03 11:18:28
I have this piece of code @Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class, exclude = URISyntaxException.class, backoff = @Backoff(delay = 1000, multiplier = 2) ) public void testThatService(String serviceAccountId) throws ServiceUnavailableException, URISyntaxException { //some implementation here } Is there a way I can make the maxAttempts , delay and multiplier configurable using @Value? Or is there any other approach to make such fields inside annotations configurable? Gary Russell It's not currently possible; to wire in properties, the annotation

spring amqp enable retry by configuration and prevent it according to a specified exception

大兔子大兔子 提交于 2019-12-02 17:53:01
问题 I have the following two cases In case of ExceptionA : retrying for finite number of times and finally when number of retrials exhausted, message is written in a dead letter queue In case of ExceptionB : simply, message should be written to dead letter queue I want to support the two cases on the same listener container factory and the same queue. I already have the following configuration to support case 1 successfully: @Bean public RetryOperationsInterceptor workMessagesRetryInterceptor() {