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

pro.chenggang.plugin.springcloud.gateway.config.GreyWeightResponseRuleConfig Maven / Gradle / Ivy

There is a newer version: 2.1.SR2.2.RELEASE
Show newest version
package pro.chenggang.plugin.springcloud.gateway.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import pro.chenggang.plugin.springcloud.gateway.grey.GreyPredicate;
import pro.chenggang.plugin.springcloud.gateway.grey.GreyWeightResponseRule;
import pro.chenggang.plugin.springcloud.gateway.grey.support.PredicateFactory;
import pro.chenggang.plugin.springcloud.gateway.offline.OfflinePredicate;
import pro.chenggang.plugin.springcloud.gateway.properties.GreyProperties;

/**
 * Gateway Plugin Config
 * @author chenggang
 * @date 2019/01/29
 */
@Slf4j
@Configuration
@ConditionalOnClass(DiscoveryEnabledNIWSServerList.class)
@AutoConfigureBefore(RibbonClientConfiguration.class)
@ConditionalOnProperty(prefix = GreyProperties.GREY_PROPERTIES_PREFIX,value = "enable",havingValue = "true")
public class GreyWeightResponseRuleConfig {

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    @ConditionalOnProperty(prefix = GreyProperties.GREY_PROPERTIES_PREFIX,value = "grey-ribbon-rule",havingValue = "WEIGHT_RESPONSE")
    public IRule ribbonRule(PredicateFactory predicateFactory, GreyProperties greyProperties) {
        GreyWeightResponseRule greyWeightResponseRule;
        if(greyProperties.getEnable()){
            greyWeightResponseRule = new GreyWeightResponseRule(predicateFactory.getAllPredicate(GreyPredicate.class,OfflinePredicate.class));
        }else{
            greyWeightResponseRule = new GreyWeightResponseRule(predicateFactory.getAllPredicate(OfflinePredicate.class));
        }
        log.debug("Load Grey Weight Response Rule Config Bean");
        return greyWeightResponseRule;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy