是否可以将参数更改为重试事件中用@Retryable 注释的 class 中的方法?

Is it possible to change the parameters to a method in a class annotated with @Retryable in the retry event?

我有一个用 @Retryable 注释的单身人士 class。在此范围内,我们使用 @Client 进行调用,并将身份验证令牌作为参数传入。

如果授权已过期,我们希望重新授权,然后使用更新的令牌重试方法调用。

我们处理了 RetryEvent 并获得了一个新令牌,但我们无法更新原始方法调用参数。方法returns一个Single

像这样:

@Retryable
@Singleton
class test {
    @Inject TestRestClient testRestClient

   Single<E> getStuff(AuthClient auth, String param) {
      testRestClient.apiCall(auth.token, param).map{ stuff -> 
         do some stuff as E
      }
   }
}

// Retry Handler

@Singleton
class AuthRetryEventListener implements ApplicationEventListener<RetryEvent> {

    @Inject
    AuthService authService

    @Override
    void onApplicationEvent(RetryEvent event) {
        MutableArgumentValue argumentValue = event.source.parameters.find{it.value.value.class in AuthClient.class}?.value
        if(argumentValue){
            AuthClient authClient = argumentValue.value as AuthClient
            authService.refresh(authClient)
            argumentValue.setValue(authClient)
        }
    }
}

这是解决这个问题的正确方法吗?如何使用更新后的参数再次调用方法?

谢谢。

@Retryable 的重点是重试原始调用。您尝试执行的操作不适合 @Retryable 的用例。这很可能更适合在过滤器中实现。