Spring-Retry

Is it possible to set RetryPolicy in spring-retry based on HttpStatus status code?

给你一囗甜甜゛ 提交于 2019-12-18 04:45:13
问题 Is it possible to set RetryPolicy in spring retry (https://github.com/spring-projects/spring-retry) based on error status code? e.g. I want to retry on HttpServerErrorException with HttpStatus.INTERNAL_SERVER_ERROR status code, which is 503. Therefore it should ignore all other error codes -- [500 - 502] and [504 - 511]. 回答1: The RestTemplate has setErrorHandler option and DefaultResponseErrorHandler is the default one. Its code looks like: public void handleError(ClientHttpResponse response)

SpringCloud相关pom依赖

荒凉一梦 提交于 2019-12-13 10:24:39
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 最近的学习方向是SpringCloud,系列,包含微服务相关知识,在最近的学习阶段中总结了一套搭建环境很稳定的pom依赖,现在一起分享给大家,本人使用过程中版本稳定,使用舒适,所以推荐 先来看一下我的项目结构 因为是一个简单的demo项目,所以结构一目了然, parent是父项目 demo是注册中心 service和client都分别是不同的服务 zuul是网关 接下来一个个去打开pom文件,分享给大家 **parent父项目 ** 只需确定版本等 ` <!-- 1 确定spring boot的版本--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> </parent> <!--2 确定版本--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <spring-cloud-release.version

logging messages on retry of rabbit message

旧街凉风 提交于 2019-12-11 03:01:52
问题 We're using RabbitMQ in our application to queue payment requests, and have another queue to send results back to the caller. In both cases, the client has requested a retry policy that will retry forever, but will put something in the log on each retry like "Retrying transaction for the xth time..." so that an external system can detect stuff backing up by monitoring the log file. I'm creating listener container thus: public SimpleMessageListenerContainer paymentListenerContainer() { final

Trying to exclude an exception using @Retryable - causes ExhaustedRetryException to be thrown

寵の児 提交于 2019-12-10 08:43:51
问题 I'm trying to use @Retryable on a method that calls the REST template. If an error is returned due to a communication error, I want to retry otherwise I want to just thrown an exception on the call. When the ApiException occurs, instead of it being thrown and ignored by @Retryable, I get an ExhaustedRetryException and a complaint about not finding enough 'recoverables', i.e, @Recover methods. I thought I'd see if just having the recoverable method present might make it happy and still perform

Spring Retry Junit: Testing Retry template with Custom Retry Policy

南楼画角 提交于 2019-12-08 13:11:33
问题 I'm trying to test a Retry template which is using a custom Retry Policy. In order to do that, I'm using this examples: https://github.com/spring-projects/spring-retry/blob/master/src/test/java/org/springframework/retry/support/RetryTemplateTests.java#L57 Basically, my goal is to test my retry logic when I got some specific http error status (for example an http 500 error status). This is the xml context for my junit: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www

Feign client and Spring retry

人走茶凉 提交于 2019-12-07 02:48:41
问题 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(

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

余生颓废 提交于 2019-12-06 16:01:46
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 ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory

Spring AMQP StatefulRetryOperationsInterceptor not used

匆匆过客 提交于 2019-12-06 05:45:33
问题 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)

Spring Retry with Transactional

感情迁移 提交于 2019-12-05 17:31:38
问题 Is Spring Retry guaranteed to work with Spring's @Transactional annotation? Specifically, I'm trying to use @Retryable for optimistic locking. It seems like it would be dependent on the ordering of the AOP proxies that were created. For example, if the calls look like this: Calling code -> Retry Proxy -> Transaction Proxy -> Actual DB Code Then it would work correctly, but if the proxies were structured like this: Calling code -> Transaction Proxy -> Retry Proxy -> Actual DB Code Then the

Trying to exclude an exception using @Retryable - causes ExhaustedRetryException to be thrown

╄→гoц情女王★ 提交于 2019-12-05 16:01:03
I'm trying to use @Retryable on a method that calls the REST template. If an error is returned due to a communication error, I want to retry otherwise I want to just thrown an exception on the call. When the ApiException occurs, instead of it being thrown and ignored by @Retryable, I get an ExhaustedRetryException and a complaint about not finding enough 'recoverables', i.e, @Recover methods. I thought I'd see if just having the recoverable method present might make it happy and still perform as hoped for. Not so much. Instead of throwing the exception, it called the recoverable method.