Skip to content

How can detect last retry? #361

@donghoon-khan

Description

@donghoon-khan

I am using Spring-retry-1.3.4, i want to detect the event before the last retry and insert logic. Is there a way? I think I can use RetryListener, but I can't.

TestService.java

    @Retryable(
            value = {Exception.class},
            maxAttempts = 2
    )
    public void test1() {
    }

    @Retryable(
            value = {Exception.class},
            maxAttempts = 3
    )
    public void test2() {
    }

    @Retryable(
            value = {Exception.class},
            maxAttempts = 4
    )
    public void test3() {
    }

MyRetryListener.java

public class MyListener implements RetryListener {
...
    public <T, E extends Throwable> void onError(
            final RetryContext context,
            final RetryCallback<T, E> callback,
            final Throwable throwable
    ) {
        if (getMaxAttemps() == context.getRetryCount()) {
            logic();
        }
    }
    
    private int getMaxAttemps() {
        ???
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions