【问题标题】:EventListener and retryableEventListener 和可重试
【发布时间】:2019-07-30 13:08:03
【问题描述】:

我想在我的应用程序启动后调用一些代码。有没有办法处理事件:

Started SomeApp in 14.905 seconds (JVM running for 16.268) 

如果另一个应用程序启动,我将尝试。我尝试使用 Retryable 但未在应用程序启动之前执行它并引发异常以便应用程序退出。

    @EventListener
    fun handleContextRefresh(event: ContextRefreshedEvent) {

        retryableInvokeConnection()
    }

    @Retryable(
        value = [RetryableException::class, ConnectionException::class],
        maxAttempts = 100000,
        backoff = Backoff(delay = 5)
    )
    private fun retryableInvokeConnection() {
    }

    @Recover
    private fun retryableInvokeConnectionExceptionHandler(ex: ConnectionException) {
    }

也许我应该使用 PostConstruct 和 while 循环。

【问题讨论】:

    标签: spring spring-cloud-feign spring-retry


    【解决方案1】:

    您不能在同一个 bean 中调用 @Retryable 方法,它使用重试拦截器绕过代理。将方法移动到另一个 bean 并注入它。

    事件是比使用@PostConstruct更好的方式。

    【讨论】:

    • 但是在应用程序启动后我该如何处理。不在启动过程中
    • nvm 你的解决方案帮助了我,我也错过了 EnableRetry
    • 请问是否有可能指定retryable重试直到成功
    • 您必须使用AlwaysRetryPolicy 创建一个外部interceptor
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多