Thursday, 2 January 2020

springboot transaction and retry (you can use this to retry any method in case of exception.)

you need to add @EnableRetry to the applicadtion 

and add @Retryable to the method which you want to retry in case of issue(if you want to do transcation retry, then you need to add this with transaction)

you need to add to jars into your project:  the retry lib and aspectj lib as well.

one thing is very important you need to make sure the caller (who call the retry method) need to in another class

you can use below code to test

private static int COUNTER = 0;
@Retryable (
      value = { Exception.class }, 
      maxAttempts = 2,
      backoff = @Backoff(delay = 50)) 
public void process(SexObj sexobj) {
if(COUNTER < 2) {"test -- -- -- - - -  will send excpetion");
throw new RuntimeException();
}"test -- -- -- - - - ");

1 comment:

  1. Your Affiliate Money Making Machine is ready -

    And making profit with it is as easy as 1---2---3!

    Here are the steps to make it work...

    STEP 1. Choose which affiliate products the system will advertise
    STEP 2. Add some PUSH BUTTON traffic (it LITERALLY takes JUST 2 minutes)
    STEP 3. See how the affiliate system explode your list and up-sell your affiliate products all for you!

    So, do you want to start making money?

    Click here to activate the system