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

org.yes.tools.config.FeignAutoConfig Maven / Gradle / Ivy

There is a newer version: 2.0.6
Show newest version
package org.yes.tools.config;

import com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.Feign;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.yes.tools.ext.SentinelFeign;
import org.yes.tools.handle.UrlBlockHandler;
import org.yes.tools.parser.HeaderRequestOriginParser;

/**
 * sentinel 配置
 *
 * @author Co.
 * @date 2023/10/24 10:24
 */
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
public class FeignAutoConfig {

    @Bean
    @Scope("prototype")
    @ConditionalOnMissingBean
    @ConditionalOnProperty(name = "feign.sentinel.enabled")
    public Feign.Builder feignSentinelBuilder() {
        return SentinelFeign.builder();
    }

    @Bean
    @ConditionalOnMissingBean
    public BlockExceptionHandler blockExceptionHandler(ObjectMapper objectMapper) {
        return new UrlBlockHandler(objectMapper);
    }

    @Bean
    public RequestOriginParser requestOriginParser() {
        return new HeaderRequestOriginParser();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy