All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nbcp.myoql.bean.MyOqlEsBeanConfig.kt Maven / Gradle / Ivy

The newest version!
package nbcp.myoql.bean

import org.elasticsearch.client.RestClientBuilder
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.BeanPostProcessor
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.stereotype.Component
import java.util.concurrent.TimeUnit

@Component
@ConditionalOnClass(RestClientBuilder::class)
class MyOqlEsBeanConfig : BeanPostProcessor {
    companion object {
        private val logger = LoggerFactory.getLogger(this::class.java.declaringClass)
    }

    override fun postProcessAfterInitialization(bean: Any, beanName: String): Any? {
        var ret = super.postProcessAfterInitialization(bean, beanName)

        //解决 长时间空闲,连接不上的错误
        if (bean is RestClientBuilder) {
            bean.setHttpClientConfigCallback {
                it.setKeepAliveStrategy { _, _ ->
                    return@setKeepAliveStrategy TimeUnit.MINUTES.toMillis(3)
                }
            }
        }
//        else if (bean is ElasticsearchRestClientProperties) {
//        }

        return ret;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy