Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
Spring
Spring-retry not working in Springboot
John Joe
Ranch Hand
Posts: 570
3
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How can I create an exception class for spring-retry in Springboot ?
@Retryable(value={SomeException.class},maxAttemptsExpression = "#{${max.read.attempts}}", backoff = @Backoff(delayExpression = "#{${retry.delay}}", multiplierExpression = "#{${multiplier}}", maxDelayExpression = "#{${max.delay}}")) @PostMapping("abc/{Id}") public void abc(@PathVariable("Id") String Id, @RequestBody Dto pos) throws ISOException, ParseException, IOException { //code try { ResponseEntity<Dto> responseEntity = restTemplate.exchange(theUrl, HttpMethod.POST, entity, Dto.class); // ..... } catch (RestClientException ex) { if (ex instanceof ResourceAccessException) { throw new SomeException(ex,pos,tran); } } } @Recover public void recover(int attempts) { log.info("Retried " + attempts + " times"); log.info("Data successfully recorded"); }
SomeException
public class SomeException extends RuntimeException { public SomeException(RestClientException message, JposDto jpos,MmcTrangloTrans trans) { super(message); } }
The spring-retry not working.
Learning language is easy but learning basics is difficult
John Joe
Ranch Hand
Posts: 570
3
I like...
posted 5 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
Have solved it using my own way.
Learning language is easy but learning basics is difficult
Paul Clapham
Marshal
Posts: 27531
88
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Let us know what that way is! You never know, somebody else might have the same problem and come here searching for solutions.
John Joe
Ranch Hand
Posts: 570
3
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm just using a simple if else instead @Recover
@Retryable(maxAttemptsExpression = "#{${max.read.attempts}}", backoff = @Backoff(delayExpression = "#{${retry.delay}}", multiplierExpression = "#{${multiplier}}", maxDelayExpression = "#{${max.delay}}")) @PostMapping("abc/{Id}") public void abc(@PathVariable("Id") String Id, @RequestBody Dto pos) throws ISOException, ParseException, IOException { //code try { ResponseEntity<Dto> responseEntity = restTemplate.exchange(theUrl, HttpMethod.POST, entity, Dto.class); // ..... } catch (RestClientException ex) { if (ex instanceof ResourceAccessException) { if (attempts >= 3) { try { log.info("Retried " + attempts + " times"); log.info("Data successfully recorded"); proceedLog(ex,pos,tran); // here I can pass the parameters instead create custom exception class } catch (Exception e1) { // code } } else { log.error(ex + ""); throw new RuntimeException(); } } } }
Learning language is easy but learning basics is difficult
John Joe
Ranch Hand
Posts: 570
3
I like...
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks for the
cow
!
Learning language is easy but learning basics is difficult
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Need help in Spring Boot
Logging @PathVariable type mismatches
A question for Spring gurus
Basic Authentication 401 Unauthorized error calling restful web service
Java Spring REST Service Json Parameter Naming
More...