Search in sources :

Example 1 with DoorGoodConfig

use of com.hummer.doorgod.service.domain.configuration.DoorGoodConfig in project hummer-framework by hummer-team.

the class ListenerConfig method getListener.

private Listener getListener() {
    return new Listener() {

        @Override
        public Executor getExecutor() {
            return null;
        }

        @Override
        public void receiveConfigInfo(String configInfo) {
            if (Strings.isNullOrEmpty(configInfo)) {
                return;
            }
            log.debug("refresh config done,config value is \n{}", configInfo);
            // parse config instance
            DoorGoodConfig doorGoodConfig = JSON.parseObject(configInfo, new TypeReference<DoorGoodConfig>() {
            });
            // refresh gateway config
            refreshGatewayRule(doorGoodConfig);
            // refresh sentinel config
            refreshSentinelConfig(doorGoodConfig);
        }
    };
}
Also used : Listener(com.alibaba.nacos.api.config.listener.Listener) DoorGoodConfig(com.hummer.doorgod.service.domain.configuration.DoorGoodConfig)

Example 2 with DoorGoodConfig

use of com.hummer.doorgod.service.domain.configuration.DoorGoodConfig in project hummer-framework by hummer-team.

the class ListenerConfig method addListener.

private void addListener(List<String> gatewayGroup, String groupId, long timeoutMillis, ConfigService configService, boolean isFirstLoading) throws NacosException {
    Set<DegradeRule> degradeRules = Sets.newConcurrentHashSet();
    Set<GatewayFlowRule> gatewayFlowRules = Sets.newConcurrentHashSet();
    Set<ApiDefinition> apiDefinitions = Sets.newConcurrentHashSet();
    for (String dataId : gatewayGroup) {
        Listener listener = getListener();
        String configVal = configService.getConfigAndSignListener(dataId, groupId, timeoutMillis, listener);
        if (!Strings.isNullOrEmpty(configVal)) {
            // refresh gateway config
            log.debug("refresh config done,config value is \n{}", configVal);
            DoorGoodConfig doorGoodConfig = JSON.parseObject(configVal, new TypeReference<DoorGoodConfig>() {
            });
            refreshGatewayRule(doorGoodConfig);
            listenerMap.put(dataId, ListenerEvent.builder().dataId(dataId).groupId(groupId).listener(listener).sentinelConfig(doorGoodConfig.getSentinelConfig()).build());
            if (isFirstLoading) {
                addSentinelConfigForInitLoad(degradeRules, gatewayFlowRules, apiDefinitions, doorGoodConfig);
            } else {
                // refresh sentinel config
                refreshSentinelConfig(doorGoodConfig);
            }
        }
    }
    firstLoadingSentinel(isFirstLoading, degradeRules, gatewayFlowRules, apiDefinitions);
}
Also used : Listener(com.alibaba.nacos.api.config.listener.Listener) DoorGoodConfig(com.hummer.doorgod.service.domain.configuration.DoorGoodConfig) ApiDefinition(com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition) GatewayFlowRule(com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule) DegradeRule(com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)

Aggregations

Listener (com.alibaba.nacos.api.config.listener.Listener)2 DoorGoodConfig (com.hummer.doorgod.service.domain.configuration.DoorGoodConfig)2 ApiDefinition (com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition)1 GatewayFlowRule (com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule)1 DegradeRule (com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule)1