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

com.nepxion.discovery.common.consul.proccessor.ConsulProcessor Maven / Gradle / Ivy

Go to download

Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent

There is a newer version: 6.22.0
Show newest version
package com.nepxion.discovery.common.consul.proccessor;

/**
 * 

Title: Nepxion Discovery

*

Description: Nepxion Discovery

*

Copyright: Copyright (c) 2017-2050

*

Company: Nepxion

* @author Haojun Ren * @version 1.0 */ import java.util.concurrent.ExecutorService; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import com.nepxion.discovery.common.consul.operation.ConsulListener; import com.nepxion.discovery.common.consul.operation.ConsulOperation; import com.nepxion.discovery.common.consul.operation.ConsulSubscribeCallback; import com.nepxion.discovery.common.entity.ConfigType; import com.nepxion.discovery.common.processor.DiscoveryConfigProcessor; import com.nepxion.discovery.common.thread.DiscoveryThreadPoolFactory; public abstract class ConsulProcessor extends DiscoveryConfigProcessor { private ExecutorService executorService = DiscoveryThreadPoolFactory.getExecutorService("consul-config"); @Autowired private ConsulOperation consulOperation; private ConsulListener consulListener; @PostConstruct public void initialize() { beforeInitialization(); String group = getGroup(); String dataId = getDataId(); logSubscribeStarted(); try { consulListener = consulOperation.subscribeConfig(group, dataId, executorService, new ConsulSubscribeCallback() { @Override public void callback(String config) { try { callbackConfig(config); } catch (Exception e) { logCallbackFailed(e); } } }); } catch (Exception e) { logSubscribeFailed(e); } logGetStarted(); try { String config = consulOperation.getConfig(group, dataId); if (config != null) { callbackConfig(config); } else { logNotFound(); } } catch (Exception e) { logGetFailed(e); } afterInitialization(); } @Override public void destroy() { if (consulListener == null) { return; } String group = getGroup(); String dataId = getDataId(); logUnsubscribeStarted(); try { consulOperation.unsubscribeConfig(group, dataId, consulListener); } catch (Exception e) { logUnsubscribeFailed(e); } executorService.shutdownNow(); } @Override public ConfigType getConfigType() { return ConfigType.CONSUL; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy