SpringCloudOpenFeign的详解

SpringCloudOpenFeign基础使用与进阶 文章目录OpenFeign一、基本使用1.1 第一个OpenFeign程序1.1 提供者1.2 消费者1.2 功能架构1.3 工作原理1.4 @FeignClient标注的参数二、进阶2.1 负载均衡/超时控制2.2 日志增强2.3 请求压缩2.4 过滤器over OpenFeign 文章目录 OpenFeign/feign: Feign makes writing java http clients easier (github.com) Spring Cloud OpenFeign 阅读详情

1. SpringCloud OpenFeign的特性

1. 概念

  1. Feign是一个声明式web Rest服务客户端。它使编写web服务客户端更容易
  2. 要使用Feign,请创建一个接口并对其使用注解进行标注
  3. 它具有可插入注释支持,包括Feign注释和JAX-RS注释
  4. Feign还支持可插拔编码器和解码器
  5. Spring Cloud增加了对Spring MVC注释的支持,并支持使用与Spring Web中默认使用的HttpMessageConverters相同的HttpMessageConverters
  6. Spring Cloud集成了Eureka、Spring Cloud CircuitBreaker以及Spring Cloud LoadBalancer,在使用Feign时提供负载均衡的http客户端

2. 简单使用

  1. 引入依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    
  2. 启动类

    @SpringBootApplication
    @EnableFeignClients
    public class Application {
    	public static void main(String[] args) {
    		SpringApplication.run(Application.class, args);
    	}
    }
    
    
  3. 标注Feign客户端

    @FeignClient("stores")
    public interface StoreClient {
    	@RequestMapping(method = RequestMethod.GET, value = "/stores")
    	List<Store> getStores();
    
    	@GetMapping("/stores")
    	Page<Store> getStores(Pageable pageable);
    
    	@PostMapping(value = "/stores/{storeId}", consumes = "application/json")
    	Store update(@PathVariable("storeId") Long storeId, Store store);
    
    	@DeleteMapping("/stores/{storeId:\\d+}")
    	void delete(@PathVariable Long storeId);
    }
    
  4. 案例总结

    1. 在@FeignClient注释中,字符串值(上面的“stores”)是一个任意的客户端名称,用于创建Spring Cloud LoadBalancer客户端

    2. 还可以使用URL属性(URL的绝对值或直接写主机名)指定请求的url路径

      1. 之前的版本,FeignClient的url属性可以单独使用,不需要再写name属性

      2. 现在,就算使用url属性,仍然需要name属性]

        @FeignClient(name = "${feign.name}", url = "${feign.url}")
        public interface StoreClient {
        }
        
    3. Spring容器中bean的名称是接口的完全限定名称。要指定自己的别名值,可以使用@FeignClient注释的qualifiers值

    4. 上面的负载均衡客户端将需要发现“stores”服务的物理地址

      1. 如果您的应用程序是Eureka客户端,那么它将在Eureka服务注册表中解析服务
      2. 如果不想使用Eureka,可以使用SimpleDiscoveryClient在外部配置中配置服务器列表
      3. 或者使用其他的客户端(例如Nacos,Consul),提供对应服务的DiscoveryClient实现该实现提供指定服务的实例
    5. Spring Cloud OpenFeign支持Spring Cloud LoadBalancer阻塞模式的所有可用特性

    6. @EnableFeignClients默认扫描标注类的包下的FeignCLient接口,如果想指定包路径或者指定FeignClient接口,可以使用

      1. @EnableFeignClients(basePackages = "com.example.clients")
      2. @EnableFeignClients(clients = InventoryServiceFeignClient.class)
    7. 默认情况下,Feign客户端是立即加载的,它还可以支持AOT,如果不想他们立即加载,可以设置为懒加载

      1. spring.cloud.openfeign.lazy-attributes-resolution=true

3. 覆盖Feign的默认配置

  1. Spring Cloud的Feign支持的一个中心概念: 命名(具名)客户端
  2. 每个Feign客户端都是组件集成的一部分,这些组件协同工作来按需请求远程服务器,我们可以使用@FeignClient注解为客户端提供一个名称
  3. Spring Cloud根据需要使用FeignClientsConfiguration配置类为每个命名的客户端创建一个独立的新的ApplicationContext。包含feign.Decoder,feign.Encoder,feign.Contract核心组件,这些都是在FeignClientsConfiguration配置类中提供的默认组件
    1. 我们可以通过使用@FeignClient注解的contextId属性来覆盖该Feign客户端的名称(name属性)
  4. Spring Cloud允许我们通过使用@FeignClient声明额外的配置来完全控制FeignClient,覆盖FeignClientsConfiguration配置的组件实例,使用@FeignClient的configuration属性
    1. 注意: 在这种使用configuration属性情况下FooConfiguration不需要加@Configuration注解
    2. 因为如果它是一个Bean,那么所有的FeignClient默认配置类FeignClientsConfiguration的对应组件配置就都不会生效,因为它默认配置类都标注了@ConditionalOnMissingBean,因为该Bean存在所有FeignClient独立的ApplicationContext的父容器中,从而使用这个配置类中配置的组件,这样它就覆盖了默认的配置
    3. 无论如何,它最终都会通过AnnotationConfigRegistry#register(applicatioContext)进行注册,最终扫描该配置类,类似与启动类的配置类效果,最终在调用FeignClient独立的ApplicationContext的refresh方法时进行解析该配置
    4. 因此,需要注意,该配置类最好不加@Configuration,这样的话,该配置仅为了指定的FeignClient生效,否则将覆盖所有FeignClient的默认配置,除非自己确实需要这样去做
@FeignClient(name = "stores", configuration = FooConfiguration.class)
public interface StoreClient {
}
public class FooConfiguration{
	// 等等其他组件覆盖FeignClientsConfiguration的默认配置
    @Bean
	public Encoder feignEncoder(ObjectProvider<AbstractFormWriter> formWriterProvider,ObjectProvider<HttpMessageConverterCustomizer> customizers) {
		return springEncoder(formWriterProvider, encoderProperties, customizers);
	}
}

4. Feign提供和支持的Bean组件

1. SpringCloud默认提供下面这些Bean

  1. Decoder
    1. beanName: feignDecoder
    2. beanType: ResponseEntityDecoder
  2. Encoder
    1. beanName: feignEncoder
    2. beanType: SpringEncoder
  3. Logger
    1. beanName: feignLogger
    2. beanType: Slf4jLogger
  4. 链路追踪相关的增强器
    1. MicrometerObservationCapability
    2. MicrometerCapability
  5. 缓存的增强器
    1. CachingCapability
  6. Contract
    1. beanName: feignContract
    2. beanType: SpringMvcContract
  7. Feign.Builder
    1. beanName: feignBuilder
    2. beanType: FeignCircuitBreaker.Builder
  8. Client (重要)
    1. beanName: feignClient
    2. beanType: FeignBlockingLoadBalancerClient(如果存在Spring Cloud LoadBalancer依赖),否则使用默认的 Client.Default,使用HttpURLConnection处理
    3. 此外,可以修改默认的Client,因为默认的处理请求的效率很低
      1. 开启okhttp:
        1. spring.cloud.openfeign.okhttp.enabled: true
      2. 开启http2client
        1. spring.cloud.openfeign.http2client.enabled: true
      3. 开启httpclient5
        1. spring.cloud.openfeign.httpclient.hc5.enabled: true
      4. 注意: 都需要导入对应的依赖才行

2. Feign没有提供默认的Bean,但是会从容器中加载的Bean

  1. Logger.Level 日志级别
  2. Retryer 重试机制,默认禁止重试
  3. ErrorDecoder 异常解码器,解析之后可以得到一个异常信息
  4. Request.Options 请求参数配置信息
  5. Collection<RequestInterceptor> 请求拦截器
  6. SetterFactory
  7. QueryMapEncoder 将参数转换为map的编码器
  8. Capability (MicrometerObservationCapability and CachingCapability)增强器

3. 覆盖Feign默认的Bean组件

  1. 方式一

    1. 全局覆盖
    @Configuration
    public class FooConfiguration {
    	@Bean
    	public Contract feignContract() {
    		return new feign.Contract.Default();
    	}
    
    	@Bean
    	public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
    		return new BasicAuthRequestInterceptor("user", "password");
    	}
    }
    
  2. 方式二

    1. 单独覆盖FeignClient
    @FeignClient(name = "stores", configuration = FooConfiguration.class)
    public interface StoreClient {
    }
    public class FooConfiguration{
    	@Bean
    	public Contract feignContract() {
    		return new feign.Contract.Default();
    	}
    }
    

5. Feign的yaml/properties配置(等价于@Bean配置)

1. 默认情况,配置类和yaml配置效果一样,都是给核心Feign进行配置,配置文件优先于@Bean配置,如果同时存在,配置文件中配置的覆盖@Bean配置的
1. 如果需要让@Bean的优先,则使用`spring.cloud.openfeign.client.default-to-properties=false`来禁用默认的配置优先
spring:
	cloud:
		openfeign:
			client:
				config:
				    # feignClient名称
					feignName:
					    // @FeignClient的url,优先取用@FeignClient的URL,再取用配置属性文件中设置的url,最后使用默认的url,http://服务名
                        url: http://remote-service.com
                        // 设置连接超时时间
						connectTimeout: 5000
						// 设置请求超时时间
						readTimeout: 5000
						// 设置日志级别
						loggerLevel: full
						// 设置异常解码器
						errorDecoder: com.example.SimpleErrorDecoder
						// 设置重试机制
						retryer: com.example.SimpleRetryer
						// 添加默认的请求参数
						defaultQueryParameters:
							query: queryValue
						// 添加默认的请求头
						defaultRequestHeaders:
							header: headerValue
						// 设置请求拦截器
						requestInterceptors:
							- com.example.FooRequestInterceptor
							- com.example.BarRequestInterceptor
						// 设置响应拦截器
						responseInterceptor: com.example.BazResponseInterceptor
						// 设置是否处理404
						dismiss404: false
						// 设置编码器
						encoder: com.example.SimpleEncoder
						// 设置解码器
						decoder: com.example.SimpleDecoder
						 // Contract 接口定义了如何根据 Java 接口的注解创建请求和解析响应
                        // Contract 接口是 Feign 的一个核心接口,它可以自定义 Feign 客户端与服务端之间的契约规则,例如支持不同的注解风格、参数传递方式等
                        // 通过实现自定义的 Contract 接口,可以更灵活地定制 Feign 客户端与服务端之间的通信行为
                        // 该类负责解析一些注解SpringMVC的注解信息,校验哪些注解是否标注错误,解析方法上的RequestMapping注解,参数上的Param注解等
                        // 解析到的注解信息,然后交给RequestTemplate
                        // 例如:
                        //  @CollectionFormat: 集合类型的数据如何传递,CSV,\t,|分割等等
                        //  @RequestMapping解析,@Param,@SpringQueryMap,@QueryMap,@RequestParam处理
                        // 该类还包含对应注解的参数解析器
						contract: com.example.SimpleContract
						// 设置将以上描述的组件进行增强的接口
        				// 该接口的定义: A enrich (A a){return a;},给你指定参数,让你增强,返回增强后的组件
						capabilities:
							- com.example.FooCapability
							- com.example.BarCapability
                        // 设置将请求参数对象转换为map的编码器
						queryMapEncoder: com.example.SimpleQueryMapEncoder
						# 开启链路追踪
						micrometer.enabled: false

6. Feign对CircuitBreaker熔断的支持

  1. 如果存在CircuitBreaker实现,可以使用配置spring.cloud.openfeign.circuitbreaker.enabled=true启用熔断

  2. 如果想禁用FeignClient的熔断支持,可以配置一个Feign.Builder的Bean,该Builder创建的代理对象不会处理熔断

    @Configuration
    public class FooConfiguration {
    	@Bean
    	// 注意: 该Bean要注册为原型的,对于每一个FeignClient都互不影响
    	@Scope("prototype")
    	public Feign.Builder feignBuilder() {
    		return Feign.builder();
    	}
    }
    
    // 如果开启了熔断,那么默认注册的Builder对象为FeignCircuitBreaker.builder,该对象创建的代理对象支持熔断机制,如果需要禁用,我们需要配置Feign.builder来禁用该Builder的注册
    @Bean
    @Scope("prototype")
    @ConditionalOnMissingBean
    @ConditionalOnBean(CircuitBreakerFactory.class)
    public Feign.Builder circuitBreakerFeignBuilder() {
        return FeignCircuitBreaker.builder();
    }
    
  3. 对于断路器的名称格式为: <feignClientClassName>#<calledMethod>(<parameterTypes>),例如``FooFeignClient#bar(),如果要修改默认的名称格式,提供一个CircuitBreakerNameResolver `Bean

    @Configuration
    public class FooConfiguration {
    	@Bean
    	public CircuitBreakerNameResolver circuitBreakerNameResolver() {
    		return (String feignClientName, Target<?> target, Method method) -> feignClientName + "_" + method.getName();
    	}
    }
    
  4. 配置属性文件配置熔断

    spring:
      cloud:
        openfeign:
          circuitbreaker:
            enabled: true
            alphanumeric-ids:
              enabled: true
    resilience4j:
     # 熔断配置
      circuitbreaker:
        instances:
          spring-cloud-order:
            minimumNumberOfCalls: 69
      # 时间超时限制配置
      timelimiter:
        instances:
          spring-cloud-order:
            timeoutDuration: 10s
    
    1. 如果想切换为以前2022.0.0版本的熔断名称,可以使用spring.cloud.openfeign.circuitbreaker.alphanumeric-ids.enabled: false配置
  5. Feign的熔断机制-服务降级

    @FeignClient(name = "test", url = "http://localhost:${server.port}/", fallback = Fallback.class)
    protected interface TestClient {
    
    	@GetMapping("/hello")
    	Hello getHello();
    
    	@GetMapping("/hellonotfound")
    	String getException();
    
    }
    // 服务降级处理类
    @Component
    static class Fallback implements TestClient {
    
    	@Override
    	public Hello getHello() {
    		throw new NoFallbackAvailableException("Boom!", new RuntimeException());
    	}
    
    	@Override
    	public String getException() {
    		return "Fixed response";
    	}
    
    }
    
    @FeignClient(name = "testClientWithFactory", url = "http://localhost:${server.port}/",
    			fallbackFactory = TestFallbackFactory.class)
    protected interface TestClientWithFactory {
    
    	@GetMapping("/hello")
    	Hello getHello();
    
    	@GetMapping("/hellonotfound")
    	String getException();
    
    }
    
    @Component
    static class TestFallbackFactory implements FallbackFactory<FallbackWithFactory> {
    
    	@Override
    	public FallbackWithFactory create(Throwable cause) {
    		return new FallbackWithFactory();
    	}
    
    }
    
    static class FallbackWithFactory implements TestClientWithFactory {
    
    	@Override
    	public Hello getHello() {
    		throw new NoFallbackAvailableException("Boom!", new RuntimeException());
    	}
    
    	@Override
    	public String getException() {
    		return "Fixed response";
    	}
    
    }
    
    1. 注意: 在当使用Feign和Spring Cloud CircuitBreaker进行服务降级时,ApplicationContext中有多个相同类型的bean,一个是FeignClient,一个为兜底的处理类。这将导致@Autowired无法工作,因为存在多个Bean。为了解决这个问题,Spring Cloud OpenFeign将所有Feign实例(FeignClient)标记为@Primary,这样Spring框架就知道要注入哪个bean

      1. 但是在某些情况下,这可能是不可取的,因为我们有自己所指定的Bean,因此要关闭此行为,请将@FeignClient的主要属性设置为false

        @FeignClient(name = "hello", primary = false)
        public interface HelloClient {
        }    
        

7. Feign对链路追踪Micrometer 的支持

  1. Feign提供了一个增强机制Capability,它可以对Fegin的核心组件进行加工,接收核心组件参数,返回类型一样的组件

  2. Micrometer链路追踪就是通过这个实现

    # 所有的FeignClient生效
    spring.cloud.openfeign.micrometer.enabled=true
    # 单个FeignClient生效
    spring.cloud.openfeign.client.config.feignName(Feign客户端名称).micrometer.enabled=true
    
    1. 通过以上配置,会自动导入两个Bean
    	@Configuration(proxyBeanMethods = false)
    	@ConditionalOnProperty(name = "spring.cloud.openfeign.micrometer.enabled", matchIfMissing = true)
    	@ConditionalOnClass({ MicrometerObservationCapability.class, MicrometerCapability.class, MeterRegistry.class })
    	@Conditional(FeignClientMicrometerEnabledCondition.class)
    	protected static class MicrometerConfiguration {
    
    		@Bean
    		@ConditionalOnMissingBean
    		@ConditionalOnBean(type = "io.micrometer.observation.ObservationRegistry")
    		public MicrometerObservationCapability micrometerObservationCapability(ObservationRegistry registry) {
    			return new MicrometerObservationCapability(registry);
    		}
    
    		@Bean
    		@ConditionalOnBean(type = "io.micrometer.core.instrument.MeterRegistry")
    		@ConditionalOnMissingBean({ MicrometerCapability.class, MicrometerObservationCapability.class })
    		public MicrometerCapability micrometerCapability(MeterRegistry registry) {
    			return new MicrometerCapability(registry);
    		}
    
    	}
    
    1. 我们可以根据需要自定设置配置属性启用或者自己手动配置下面两个Bean

8. Feign的细节配置

  1. 如果存在多个相同服务名称的FeignClient,我们需要使用contextId属性进行表示,防止Bean名称冲突

    @FeignClient(contextId = "fooClient", name = "stores", configuration = FooConfiguration.class)
    public interface FooClient {
    }
    
    @FeignClient(contextId = "barClient", name = "stores", configuration = BarConfiguration.class)
    public interface BarClient {
    }
    
  2. 如果想让某一个FeignClient的独立ApplicationContext不继承父容器的Bean信息,这样也可以达到配置隔离,但是可能会有,所有的Bean都有FeignClient自身的ApplicationContext产生,我们可以使用FeignClientConfigurer配置

    @Configuration
    public class CustomConfiguration {
    	@Bean
    	public FeignClientConfigurer feignClientConfigurer() {
    		return new FeignClientConfigurer() {
    			@Override
    			public boolean inheritParentConfiguration() {
    				 return false;
    			}
    		};
    	}
    }
    
  3. 默认情况下,Feign不会解码"/“,例如”/“编码为”%2F",“%2F"解码为”/“,可以通过spring.cloud.openfeign.client.decodeSlash: false则会进行解码,将”%2F"解码为"/"

  4. SpringEncoder编码器,将请求参数编码为请求体对象,编码为请求体默认字符集固定为UTF-8,如果需要修改这种行为,则spring.cloud.openfeign.encoder.charset-from-content-type: true

  5. 如果想使用自定义的FeignClient客户端,不使用Feign自动创建的代理对象,我们可以仿照源码操作

    @Import(FeignClientsConfiguration.class)
    class FooController {
    
    	private FooFeignClient fooClient;
    
    	private FooFeignClient adminClient;
    
    	@Autowired
    	public FooController(Client client, Encoder encoder, Decoder decoder, Contract contract, MicrometerObservationCapability micrometerObservationCapability) {
    		this.fooClient = Feign.builder().client(client)
    				.encoder(encoder)
    				.decoder(decoder)
    				.contract(contract)
    				.addCapability(micrometerObservationCapability)
    				.requestInterceptor(new BasicAuthRequestInterceptor("user", "user"))
    				.target(FooClient.class, "https://PROD-SVC");
    
    		this.adminClient = Feign.builder().client(client)
    				.encoder(encoder)
    				.decoder(decoder)
    				.contract(contract)
    				.addCapability(micrometerObservationCapability)
    				.requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin"))
    				.target(FooClient.class, "https://PROD-SVC");
    	}
    }
    
  6. 在Feign中,FeignClient接口是可以作为模板进行继承和实现的,例如

    1. FeignClient接口不应该在服务器(接收请求端)和客户端(发送请求端)之间共享,并且不在支持类级别上的@RequestMapping标注
    public interface UserService {
    	@GetMapping("/users/{id}")
    	User getUser(@PathVariable("id") long id);
    }
    @RestController
    public class UserResource implements UserService {
    
    }
    @FeignClient("users")
    public interface UserClient extends UserService {
    
    }
    
  7. 开启请求响应GZip压缩(OkHttp默认支持GZip压缩,如果启用了OkHttp,则默认开启)

    # 开启响应的GZIP压缩功能
    spring.cloud.openfeign.compression.response.enabled=true
    # 开启请求的GZIP压缩功能
    spring.cloud.openfeign.compression.request.enabled=true
    # 触发压缩的请求数据类型
    spring.cloud.openfeign.compression.request.mime-types=text/xml,application/xml,application/json
    # 最小触发的压缩大小KB
    spring.cloud.openfeign.compression.request.min-request-size=2048
    
  8. Feign的日志配置

    1. yml配置

      1. 配置指定FeignClient的日志级别

        logging.level.project.user.UserFeignClient: DEBUG

    2. 使用@Bean配置

      1. 只需要提供Logger.Level这个Bean,并给定日志级别
        1. 全局的和FeignClient独立的参考覆盖默认配置
      @Configuration
      public class FooConfiguration {
      	@Bean
      	Logger.Level feignLoggerLevel() {
      		return Logger.Level.FULL;
      	}
      }
      
  9. Feign的缓存配置

  10. 如何开启了缓存 @EnableCaching,会自动增强InvocationHandlerFactory,该类是增强创建代理对象执行器InvocationHandler的厂,因此我们创建代理对象的InvocationHandler也具有了缓存的功能

    public class CachingCapability implements Capability {
    
        // Spring对缓存创建代理对象的拦截器,只需要执行该拦截器的invoke方法就会触发缓存操作
    	private final CacheInterceptor cacheInterceptor;
    
    	public CachingCapability(CacheInterceptor cacheInterceptor) {
    		this.cacheInterceptor = cacheInterceptor;
    	}
    
    	@Override
    	public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
    		return new FeignCachingInvocationHandlerFactory(invocationHandlerFactory, cacheInterceptor);
    	}
    
    }
    
    public class CachingCapability implements Capability {
    
    	private final CacheInterceptor cacheInterceptor;
    
    	public CachingCapability(CacheInterceptor cacheInterceptor) {
    		this.cacheInterceptor = cacheInterceptor;
    	}
    
    	@Override
    	public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
    		return new FeignCachingInvocationHandlerFactory(invocationHandlerFactory, cacheInterceptor);
    	}
    
    }
    
  11. 使用缓存

    public interface DemoClient {
    	@GetMapping("/demo/{filterParam}")
    	// 缓存接口的结果
        @Cacheable(cacheNames = "demo-cache", key = "#keyParam")
    	String demoEndpoint(String keyParam, @PathVariable String filterParam);
    }
    
  12. 转发报文头的支持

    spring.cloud.loadbalancer.x-forwarded.enabled=true
    
  13. OAuth2的支持

    spring.cloud.openfeign.oauth2.enabled=true
    
  14. 注解支持

    1. @QueryMap

      1. 将请求参数自动转换为Map,使用Map接收参数
       @RequestLine("GET /api/data")
      void getData(@QueryMap Map<String, Object> queryParams);
      
    2. @SpringQueryMap

      1. 将请求参数自动转换为JavaBean对象
      @GetMapping(path = "/demo")
      String demoEndpoint(@SpringQueryMap Params params);
      
    3. @MatrixVariable矩阵变量

      @GetMapping("/objects/links/{matrixVars}")
      Map<String, List<String>> getObjects(@MatrixVariable Map<String, List<String>> matrixVars);
      
    4. @CollectionFormat

      1. 将集合类型的参数以指定的格式进行编码
      @FeignClient(name = "demo")
      protected interface DemoFeignClient {
      
          @CollectionFormat(feign.CollectionFormat.CSV)
          @GetMapping(path = "/test")
          ResponseEntity performRequest(List<String> test);
      
          @RequestLine("GET /api/resource?ids={ids}")
          void getResource(@Param(value = "ids", collectionFormat = CollectionFormat.CSV) List<String> ids);
      
      }
      
  15. FeignClinet中URL的配置

```
// 指定url发送请求,不支持负载均衡,并且url不会再刷新(即使配置属性发生改变)
@FeignClient(name="testClient", url="http://localhost:8081")
# 等价于下面,如果同时存在,则@FeignClient生效
spring.cloud.openfeign.client.config.testClient.url=http://localhost:8081

// 组合配置,请求到指定的url,该url可以被刷新,当配置属性发生改变的时候,该FeignClient请求的url会进行刷新
@FeignClient(name="testClient")
spring.cloud.openfeign.client.config.testClient.url=http://localhost:8081
# 开启URL刷新机制,中将该URL当成事一个Bean,当发送请求的时候,从这个Bean中获取url
spring.cloud.openfeign.client.refresh-enabled=true

// 最简配置,按照Feign客户端名称解析,所有的系统自动处理,支持负载均衡
@FeignClient(name="testClient")
```
  1. 对Feign构造好的Request对象进行加工转换的扩展类LoadBalancerFeignRequestTransformer

    1. 该对象返回的Request对象才是最终发送请求的Reqeust对象
    @Bean
    public LoadBalancerFeignRequestTransformer transformer() {
    	return new LoadBalancerFeignRequestTransformer() {
    
    		@Override
    		public Request transformRequest(Request request, ServiceInstance instance) {
    			Map<String, Collection<String>> headers = new HashMap<>(request.headers());
    			headers.put("X-ServiceId", Collections.singletonList(instance.getServiceId()));
    			headers.put("X-InstanceId", Collections.singletonList(instance.getInstanceId()));
    			return Request.create(request.httpMethod(), request.url(), headers, request.body(), request.charset(),
    					request.requestTemplate());
    		}
    	};
    }
    

2. SpringCloud LoadBalance负载均衡

1. 概念

  1. Spring Cloud提供了自己的客户端负载均衡器的抽象和实现
  2. 对于负载均衡机制,增加了ReactiveLoadBalancer接口,并为其提供了基于轮询和随机的实现。
  3. 为了从响应式中选择服务实例,使用了ServiceInstanceListSupplier,支持ServiceInstanceListSupplier基于服务发现的实现,它使用类路径中可用的DiscoveryClient(注册中心)中检索可用实例
  4. 负载均衡官网

2. 功能

  1. 依赖

    <dependency>
    	<groupId>org.springframework.cloud</groupId>
    	<artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
    
  2. 开启与禁用负载均衡(默认启用)

    spring.cloud.loadbalancer.enabled=false
    
  3. 默认情况下LoadBalancerClient是懒加载的,只有在第一次负载均衡的时候才会加载该实例

    public class BlockingLoadBalancerClient implements LoadBalancerClient {
    	@Override
    	public <T> ServiceInstance choose(String serviceId, Request<T> request) {
    		// 这里才会加载loadBalancerClient
    		ReactiveLoadBalancer<ServiceInstance> loadBalancer = loadBalancerClientFactory.getInstance(serviceId);
    		if (loadBalancer == null) {
    			return null;
    		}
    		Response<ServiceInstance> loadBalancerResponse = Mono.from(loadBalancer.choose(request)).block();
    		if (loadBalancerResponse == null) {
    			return null;
    		}
    		return loadBalancerResponse.getServer();
    	}
    }
    
    1. 如果想要LoadBalancerClient立即加载,则可以使用spring.cloud.loadbalancer.eager-load.clients配置

      spring.cloud-loadbalancer.eager-load.clients[0]=my-first-client
      spring.cloud-loadbalancer.eager-load.clients[1]=my-second-client
      
      // 实现原理
      @Bean
      public LoadBalancerEagerContextInitializer loadBalancerEagerContextInitializer(
      LoadBalancerClientFactory clientFactory, 
      // 该配置就是spring.cloud-loadbalancer.eager-load,而下面就是获取该配置的客户端进行加载
      LoadBalancerEagerLoadProperties properties) {
      	return new LoadBalancerEagerContextInitializer(clientFactory, properties.getClients());
      }
      // 监听容器准备完成事件
      public LoadBalancerEagerContextInitializer implements ApplicationListener<ApplicationReadyEvent> {
      	@Override
      	public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
      		serviceNames.forEach(factory::getInstance);
      	}
      }
      
  4. 切换默认的负载均衡算法

    1. 默认的负载均衡算法为轮训

      @Configuration(proxyBeanMethods = false)
      @ConditionalOnDiscoveryEnabled
      public class LoadBalancerClientConfiguration {
      	@Bean
      	@ConditionalOnMissingBean
      	public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer(Environment environment,
      			LoadBalancerClientFactory loadBalancerClientFactory) {
      		String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
      		return new RoundRobinLoadBalancer(
      				loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), name);
      	}
      }
      
    2. 如果需要切换负载均衡算法,则可以提供该Bean

      1. 设置为随机算法

        public class CustomLoadBalancerConfiguration {
        
        	@Bean
        	ReactorLoadBalancer<ServiceInstance> randomLoadBalancer(Environment environment,
        			LoadBalancerClientFactory loadBalancerClientFactory) {
        		String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
        		return new RandomLoadBalancer(loadBalancerClientFactory
        				.getLazyProvider(name, ServiceInstanceListSupplier.class),
        				name);
        	}
        }
        
SpringCloud——OpenFeign详解 目录 一、OpenFeign介绍 1、概念 2、作用 3、架构图 二、OpenFeign案例 1、案例说明 2、搭建Eureka服务端 (1)创建maven工程 (2)导入依赖 (3)配置application.yml (4)创建主启动类 (5)启动Eureka注册中心 3、搭建服务提供者Provider80 (1)创建maven工程 (2)导入依赖 (3)配置application.yml (4)创建启动类 (5)创建controller ...... 阅读详情

相关推荐

SpringCloud OpenFeign 完整学习指南

《OpenFeign微服务调用框架全解析》 摘要:本文全面介绍了Spring Cloud生态中的声明式HTTP客户端OpenFeign。首先对比了OpenFeign与传统RestTemplate的差异,突出其声明式编程的优势。然后详细剖析了OpenFeign的工作原理和核心组件,包括代理生成、请求构建和服务发现机制。文章提供了从基础配置、注解使用到高级特性的完整教程,涵盖了超时控制、重试机制、编解码器配置等关键功能。特别介绍了与Sentinel、Resilience4j等熔断组件的集成方案,并通过电商系统案

weixin_51040479的博客 1234

SpringCloud全家桶---OpenFeign

1、SpringCloud全家桶—注册中心Eureka搭建 2、SpringCloud全家桶—注册中心Eureka高可用环境搭建 3、SpringCloud全家桶—客户端负载均衡Ribbon 4、SpringCloud全家桶—OpenFeign OpenFeign OpenFeign是一种声明式、模板化的HTTP请求,相比前面我们使用RestTemplate的方式,OpenFeign能够更加的便捷、优雅的完成微服务之间的HTTP调用。 OpenFeign的使用也非常简单,通过注解的方式即可完成,使调用者感觉

自律使我自由 1281

SpringCloud之OpenFeign:OpenFeign与Feign谁更适合你的SpringCloud项目?

OpenFeign是一种声明式的Web服务客户端,它使得编写Web服务客户端变得更加容易。在Spring Cloud微服务架构中,服务之间的通信是非常关键的,而OpenFeign正是为了简化这种服务间通信而设计的。OpenFeign以其简洁的接口定义和自动化的服务调用机制,成为了Spring Cloud微服务架构中服务间通信的重要组件。它不仅简化了服务调用的代码编写,还提供了良好的错误处理和性能优化机制,使得微服务之间的协作更加高效和稳定。

邓邓子的博客 2055

SpringCloud 服务调用 spring-cloud-starter-openfeign

spring-cloud-starter-openfeign 是 Spring Cloud 中的一个组件,用于在微服务架构中声明式地调用其他服务。它基于 Netflix 的 Feign 客户端进行了封装和增强,使其与 Spring Cloud 生态更好地集成。

王小工小工历程 2736

VSAN数据救援实战:当26个虚拟机突然不可访问时我们做了什么?

本文深度复盘了一次由运维操作失误引发的VMware vSAN存储危机,导致26个虚拟机数据不可访问的实战救援过程。文章详细剖析了vSAN脑裂状态的诊断方法,分享了在官方支持受限时,如何结合社区智慧与自主分析,通过精准的底层命令干预和状态推理,最终成功恢复全部数据的破局思路与操作细节,为vSAN数据救援提供了宝贵经验。

weixin_35749786的博客 241

视频编解码——视频编解码器工作原理

目录什么是视频编解码器为什么需要视屏编解码器视频编码器与数字视频容器时评编码器的历史 什么是视频编解码器 简单来说就是用于压缩或解压数字视频的软件或硬件 编码是信息从一种形式或格式转换为另一种形式的过程,解码是编码的反向。 适用于视频 编码是将视频、音频的原始格式的文件通过压缩技术转换成另一种格式(视频如h.264,h.265,m-jpeg等)。 解码是编码的反向过程。应用中,一般是将h.264,h.265格式数据解码成如YUV格式裸流交给显示器显示。 为什么需要视屏编解码器 需要在有限的带宽或存储空间

路人coder 1万+

@FeignClient注解

https://juejin.cn/post/6844904039595917319

loet6010的博客 2万+

MATLAB并行开不了的解决办法

在服务器上新安装了MATLAB 2013b,在开并行计算的时候出现了下列问题 经过在网上搜多这个问题,我感觉这个问题应该是安装的时候的验证问题或者激活不成功之类的。注意其中有一句validate the profile ‘local’ in the Cluster Profile Manager.在matlab官网上找到了设置Cluster Manager的教程,如下 parallel>

sinat_36713319的博客 5991

使用SpringCloudOpenFeign进行微服务调用

1.背景介绍 在现代软件开发中,微服务架构已经成为一种非常流行的模式。微服务架构涉及将单个应用程序拆分成多个小服务,这些服务可以独立部署和扩展。这种架构的一个关键组成部分是微服务之间的通信。Spring Cloud OpenFeign 是一个用于在微服务中进行远程调用的框架,它提供了一种简单、高效的方式来处理微服务之间的通信。 在本文中,我们将深入探讨如何使用 Spring Cloud Ope...

AI天才研究院 1041

QGIS:安装Deepness插件+应用

简单的描述了deepness的安装应用历程,重点是记录博主本次遇到的坑

fengyi157的博客 2360

LangChain + Milvus Lite:从零搭建本地RAG知识库

本文详细介绍了如何利用LangChain、Milvus Lite和gte-large-zh模型,在本地从零搭建一个完整的RAG知识库系统。文章涵盖了环境配置、文档处理与向量化、本地向量库构建以及检索问答实现的全流程,重点突出了完全本地化部署带来的数据隐私安全和成本优势,为开发者提供了一条实践性极强的技术路径。

weixin_29044713的博客 454

Spring Cloud OpenFeign 关键知识详解

Spring Cloud OpenFeign 全教程

深圳市多克创新科技有限公司 1229

spring-ai 1.0.0 学习(四)——提示词管理

摘要:本文介绍Spring AI中提示词管理的最佳实践。首先展示基础样例,指出直接传递用户输入的局限性。随后分析优质提示词应包含系统消息、上下文信息、输出结构和问答样例四要素。文章详述两种实现方式:链式调用(使用ChatClient构建器)和传统对象创建方法。进阶部分涵盖核心接口(Prompt、Message等)、消息类型、模板渲染配置(支持自定义)及提示词工程技巧(如RAG、任务分解)。最后提及高级功能如少样本模板和提示词库。全文强调结构化提示词对提升AI输出质量的关键作用,并展示Spring AI的灵活

hzp的专栏 1367

SpringCloudOpenFeign奇淫技巧

SpringCloudOpenFeign奇淫技巧

bearboy80的专栏 596

【图像超分】论文精读:RepSR: Training Efficient VGG-style Super-Resolution Networks with Structural Re-Paramete

摘要: 本文提出RepSR,一种基于结构重新参数化和批量归一化(BN)的高效VGG式超分辨率网络。针对SR任务中BN易引发伪影的问题,作者通过分析发现训练-测试阶段的不一致性是主因,并提出先使用小批量统计训练、后期切换为总体统计的优化策略。RepSR块设计包含干净的残差路径和带改进BN的扩展-压缩卷积路径,有效平衡了训练非线性与推理效率。实验表明,RepSR在不同模型规模下优于现有重参数化方法,且实际推理速度更快。该工作为SR提供了性能与效率兼优的解决方案,相关代码未开源。 关键词: 超分辨率、结构重参数化

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 318

python实现DoIP基本通信(收发报文)

python实现DoIP基本通信(收发报文)

天赐好车的博客 904

SpringCloudOpenFeign

feign feign是一个远程客户端 他的核心是feignclient,内部实际上是一个动态代理,把requestMapping上的地址 拼接成目标地址 Feign要做的事情 参数的解析和装载 针对指定的feignClient,生成动态代理 针对FeignClient中的方法描述进行解析 组装出一个Request对象,发起请求 Bean的动态装载 所有实现了该接口的类的都会被ConfigurationClassPostProcessor处理,ConfigurationClassPostProces

zquwei的博客 248

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

服务调用/通信-OpenFeign最佳实践

Spring Cloud OpenFeign 它是 Spring 官方推出的一种声明式服务调用与负载均衡组件。它底层基于 Netflix Feign,Netflix Feign 是 Netflix 设计的开源的声明式 WebService 客户端,用于简化服务间通信。Spring Cloud openfeign 对 Feign 进行了增强,使其支持 Spring MVC 注解,另外还整合了 Ribbon 和 Nacos,从而使得 Feign 的使用更加方便。

Linn的博客 1270

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

SpringCloud - 服务调用组件OpenFeign使用详解(二)

Spring Cloud Feign 是基于 Netflix feign 实现,整合了 Spring Cloud Ribbon 和 Spring Cloud Hystrix,除了提供这两者的强大功能外,还提供了一种声明式的 Web 服务客户端定义的方式。提供了更高层次的封装来整合这两个基础工具以简化开发。......

记录并分享 550

Springcloud OpenFeign 的实现(二)

Springcloud OpenFeign 的实现(二)

深圳市多克创新科技有限公司 1890

OpenFeign 入门教程 - 基础篇

目录 Spring Cloud OpenFeign 介绍 Feign 概述 Spring Cloud OpenFeign 概述 Spring Cloud OpenFeign 的特性 Feign 与 Spring Cloud OpenFeign 的选择 Spring Cloud OpenFeign 入门案例 1. 版本说明 2. 创建 Maven 父级 Pom 工程 3. 创建 Eureka Server 工程 4. 创建 Provider 源服务工程 5. 创建 Feign Clien

qq_43783527的博客 3566

Spring Cloud OpenFeign

Spring Cloud OpenFeign整合了Spring Cloud Ribbon、Spring Cloud Hystrix,同时还实现重试机制。 maven依赖 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId

不务正业的野猴子 722

基于SpringCloudOpenFeign的token的传递(上)

基于SpringCloudFeign的token传递

shushengcoder的博客 1423

Spring Cloud OpenFeign服务调用的传参方式

Spring Cloud OpenFeign是一种声明式的Web服务客户端,它使得编写Web服务客户端变得更加容易。通过使用OpenFeign,开发者可以定义一个接口并使用注解来声明如何调用服务,而无需手动实现具体的调用逻辑。通过本博客的介绍,你应该对Spring Cloud OpenFeign中服务调用的传参方式有了更深入的了解。无论是路径参数、请求参数还是请求体参数,OpenFeign都提供了便捷的方式来处理服务调用中的参数传递问题,使得微服务架构中的服务调用更加简洁和灵活。

Java老兵的后端进阶与AI前沿探索之路。 812

SpringCloudOpenFeign的核心组件总结

【代码】SpringCloudOpenFeign的核心组件总结。

JavaMyDream的博客 688

JAVA面试题分享三百八十八:最详细的OpenFeign讲解

OpenFeign是一个非常有用的工具,它为开发者提供了一种简单而强大的方式来处理远程服务调用。通过使用OpenFeign,开发者可以专注于业务逻辑,而无需花费太多精力在复杂的网络编程细节上。OpenFeign的声明式编程风格使得我们能够以一种高度抽象和简洁的方式与远程服务进行交互,它简化了网络请求的构建和发送过程,降低了开发的复杂度。总的来说,Spring Cloud OpenFeign是一个强大而灵活的工具,它可以帮助开发者更高效地构建和维护微服务应用。

之乎者也·的博客 1619
上一篇: SpringCloudOpenFeign的核心组件总结
下一篇: SpringCloud中@EnableDiscoveryClient的源码解析
安缇吖
博客等级 码龄9年 411粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址