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

com.github.zuihou.cloud.OpenFeignAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
package com.github.zuihou.cloud;

import com.github.zuihou.cloud.hystrix.ThreadLocalHystrixConcurrencyStrategy;
import com.github.zuihou.cloud.interceptor.FeignAddHeaderRequestInterceptor;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * OpenFeign 配置
 *
 * @author zuihou
 * @date 2019/07/25
 */
public class OpenFeignAutoConfiguration {
    /**
     * 在feign调用方配置, 解决入参和出参是 date 类型
     *
     * @return
     */
    @Bean
    public DateFormatRegister dateFormatRegister() {
        return new DateFormatRegister();
    }

    /**
     * feign 表单编码
     *
     * @return
     */
    @Bean
    public Encoder feignFormEncoder() {
        List> converters = new RestTemplate().getMessageConverters();
        ObjectFactory factory = () -> new HttpMessageConverters(converters);
        return new SpringFormEncoder(new SpringEncoder(factory));
    }

    /**
     * feign client 请求头传播
     *
     * @return
     */
    @Bean
    public FeignAddHeaderRequestInterceptor getClientTokenInterceptor() {
        return new FeignAddHeaderRequestInterceptor();
    }

    /**
     * 本地线程 Hystrix并发策略
     *
     * @return
     */
    @Bean
    public ThreadLocalHystrixConcurrencyStrategy getThreadLocalHystrixConcurrencyStrategy() {
        return new ThreadLocalHystrixConcurrencyStrategy();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy