Spring-Retry

Ensure single instance of a spring managed bean

柔情痞子 提交于 2020-01-11 11:18:36
问题 I have created a spring aspect to handle Retry mechanism. I have also created a Retry annotation. Following is the code for Retry annotation and an aspect which processes this annotation. @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Retry { /** * List of exceptions for which we need to retry method invocation. * * @return Array of classes. */ Class<?>[] exceptions(); /** * Number of retries. Default is 3. * * @return Number of retires. */ int retries()

Ensure single instance of a spring managed bean

左心房为你撑大大i 提交于 2020-01-11 11:18:07
问题 I have created a spring aspect to handle Retry mechanism. I have also created a Retry annotation. Following is the code for Retry annotation and an aspect which processes this annotation. @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Retry { /** * List of exceptions for which we need to retry method invocation. * * @return Array of classes. */ Class<?>[] exceptions(); /** * Number of retries. Default is 3. * * @return Number of retires. */ int retries()

Spring boot使用spring retry重试机制

那年仲夏 提交于 2020-01-06 19:32:00
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 当我们调用接口的时候由于网络原因可能失败,再尝试就成功了,这就是重试机制。非幂等的情况下要小心使用重试。 tips:幂等性 HTTP/1.1中对幂等性的定义是:一次和多次请求某一个资源对于资源本身应该具有同样的结果(网络超时等问题除外)。也就是说,其任意多次执行对资源本身所产生的影响均与一次执行的影响相同。 注解方式使用Spring Retry (一)Maven依赖 <!-- 重试机制 --> <dependency> <groupId>org.springframework.retry</groupId> <artifactId>spring-retry</artifactId> <version>1.2.4.RELEASE</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.9.4</version> </dependency> (二)配置类添加注解 @EnableRetry @EnableRetry @Configuration public class RetryConfiguration { } (三

How to set acknowledgement in case when retry gets exhausted in Kafka consumer

寵の児 提交于 2020-01-02 21:53:11
问题 I have a Kafka consumer which retry 5 time and I am using Spring Kafka with retry template . Now if all retry are failed then how to does acknowledge work in that case . Also if i have set acknowledge mode to manually then how to acknowledge those message Consumer @Bean("kafkaListenerContainerFactory") public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(RetryTemplate retryTemplate) { ConcurrentKafkaListenerContainerFactory<String, String> factory = new

RabbitMQ & Spring amqp retry without blocking consumers

做~自己de王妃 提交于 2019-12-25 03:58:22
问题 I'm working with RabbitMQ and Spring amqp where I would prefer not to lose messages. By using exponential back off policy for retrying, I'm potentially blocking my consumers which they could be working off on messages they could handle. I'd like to give failed messages several days to retry with the exponential back off policy, but I don't want a consumer blocking for several days and I want it to keep working on the other messages. I know we can achieve this kind of functionality with

Ribbon Retry properties not respected

南楼画角 提交于 2019-12-24 10:35:59
问题 I have a zuul gateway application, that receives requests from a client app and forwards the requests using load balanced rest template to a micro service with 2 endpoints, say endpoint1 and endpoint2 (load balancing between the two end points in round robbin which is okay for now, although I want it to be availability based). Here are the issues I am facing - I brought down one of the end points, say endpoint2 and tried calling the zuul route and I see that when the request is going to the

Read maxAttempts of spring @Retryable from application.properties file

泄露秘密 提交于 2019-12-23 23:51:31
问题 @Retryable(value = Exception.class, maxAttempts = 3) public Boolean sendMessageService(Request request){ ... } maxAttempts argument in @Retryable annotation is hard coded. Can i read that value from application.properties file? something like @Retryable(value = Exception.class, maxAttempts = "${MAX_ATTEMPTS}") 回答1: No; it's not possible to set via a property when using the annotation. You can wire up the RetryOperationsInterceptor bean manually and apply it to your method using Spring AOP...

Stop Spring Cloud Stream @StreamListener from listening when target system is down

拥有回忆 提交于 2019-12-23 17:27:40
问题 I have an application that gets messages from Kafka and calls a target system to update a legacy Oracle DB. I want to enable a scenario where if the target system is down, to leave the messages on Kafka bus and not process them for a given period of time. I was thinking of some Circuit-breaker Hystrix-based solution, but I can't find any mechanism to tell Spring Cloud Stream to "stop" the event listening. The only other alternative I can think of is if the circuit breaker is open, to transfer

Spring Retry @Recover passing parameters

流过昼夜 提交于 2019-12-22 06:45:09
问题 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

Spring Kafka SeekToCurrentErrorHandler Find Out Which Record Has Failed

戏子无情 提交于 2019-12-21 05:13:19
问题 I have implemented a Kafka consumer with KafkaHandler . My consumer is supposed to consume events, then send a REST request to some other service for each event. I want to retry only if that REST service is down. Otherwise, I can ignore the failed event. My container factory is configured as below: @Bean public ConcurrentKafkaListenerContainerFactory<String, MyCustomEvent> kafkaListenerContainerFactory() { ConcurrentKafkaListenerContainerFactory<String, MyCustomEvent> factory = new