标签: spring-cloud-feign

Spring Cloud:Feign和Http连接池

任何人都可以告诉我Spring Cloud Feign客户端是否提供或支持Http连接池,如果是,如何配置池大小等设置?我似乎无法在官方文档中找到这个.谢谢.

connection-pooling netflix-feign spring-cloud-feign

6
推荐指数
1
解决办法
3257
查看次数

微服务之间的安全性

我有两个微服务,例如 A 和 B。微服务 B 的其余端点必须只能从微服务 A 访问。如何限制微服务之间的访问?如果可能,最佳实践是什么?

我正在使用 spring 云安全(oauth2,jwt)。

spring-security microservices spring-cloud-feign spring-cloud-security

6
推荐指数
1
解决办法
4069
查看次数

当实例关闭并转发到其他可用实例时,Spring cloud Zuul重试

使用'Camden.SR5'来实现spring-cloud-dependencies,使用spring boot'1.5.2.RELEASE'.

在我目前的设置中,我有

  • 尤里卡服务器
  • 配置服务器(在随机端口上运行)
  • zuul网关服务器
  • 和2个服务实例(在随机端口上运行)

所有这些实例都成功注册了Eureka.

在此输入图像描述

当所有服务都在运行时,负载均衡通过zuul正确完成,没有任何问题.

当一个实例被杀死时,Zuul仍在尝试使用相同的服务来完成请求.但是,如果在关闭实例后等到eureka注册表被提取,请求将与其他"UP"实例一起完成.

    2017-03-07 19:57:41.409 DEBUG 26658 --- [nio-5555-exec-3] c.n.l.reactive.LoadBalancerCommand       : Got error org.apache.http.conn.HttpHostConnectException: Connect to 10.99.4.151:64381 [/10.99.4.151] failed: Connection refused when executed on server 10.99.4.151:64381
2017-03-07 19:57:41.420 DEBUG 26658 --- [nio-5555-exec-3] com.netflix.hystrix.AbstractCommand      : Error executing HystrixCommand.run(). Proceeding to fallback logic ...

com.netflix.client.ClientException: null
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:123) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:81) ~[ribbon-loadbalancer-2.2.0.jar:2.2.0]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.run(AbstractRibbonCommand.java:96) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.support.AbstractRibbonCommand.run(AbstractRibbonCommand.java:42) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar:1.2.5.RELEASE]
Run Code Online (Sandbox Code Playgroud)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75) ~[httpclient-4.5.3.jar:4.5.3]
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) ~[httpclient-4.5.3.jar:4.5.3]
    ... 162 common frames omitted

2017-03-07 19:57:41.425 DEBUG 26658 --- [nio-5555-exec-3] …
Run Code Online (Sandbox Code Playgroud)

microservices spring-cloud netflix-zuul spring-cloud-feign spring-cloud-netflix

6
推荐指数
1
解决办法
3984
查看次数

在使用Feys with Hystrix时,如何允许400个错误传播?

我正在构建一个调用另一个微服务的SpringBoot微服务,并且自然希望使用Hystrix和Feign客户端,它们都包含在Spring Cloud中.我正在使用版本Camden.SR5.

对于Feign的任何超时,连接失败和50x响应代码,我希望Hystrix能够正常启动并正常工作:绊倒断路器并调用回退(如果已配置)等.默认情况下这样做,所以我很好.

但对于40x响应代码,包括无效输入,错误的字段格式等,我希望Hystrix将这些异常传播给调用者,所以我也可以按照我的选择来处理它们.这不是我观察到的默认值.如何配置Hystrix/Feign在Spring Cloud中执行此操作?

使用以下代码开箱即用:

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.hateoas.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(name = "dog-service", url = "http://...")
public interface DogsFeignClient {
  @RequestMapping(method = RequestMethod.POST, path = "/dogs")
  Resource<Dog> createDog(Dog dog);
}
Run Code Online (Sandbox Code Playgroud)

生成此异常,这不适合将40x响应很好地传递给调用者:

com.netflix.hystrix.exception.HystrixRuntimeException: DogsFeignClient#createDog(Dog) failed and no fallback available.
    at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:805) ~[hystrix-core-1.5.6.jar:1.5.6]
    ....lines ommited for brevity....
Caused by: feign.FeignException: status 400 reading DogsFeignClient#createDog(Dog); content:
{
  "errors" : [ {
    "entity" : "Dog",
    "property" : "numberOfLegs",
    "invalidValue" : "3",
    "message" : "All dogs must have 4 legs" …
Run Code Online (Sandbox Code Playgroud)

java spring hystrix spring-cloud spring-cloud-feign

6
推荐指数
1
解决办法
1万
查看次数

spring boot 2 + feign + eureka 客户端不会将服务名称解析为 URL

我正在尝试使用 spring-cloud (Finchley.SR1) 的 spring-boot (2.0.5) 并尝试使用 Eureka 作为发现服务器和 Feign/Ribbon 作为客户端来设置两个服务之间的通信。设置非常简单(尽管我尝试过的各种事情和其他答案有点混乱):

Eureka 的应用程序.yml

spring:
  application:
    name: eureka-service
server:
  port: 8761
eureka:
  instance:
    hostname: localhost
    preferIpAddress: true
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
Run Code Online (Sandbox Code Playgroud)

第二个服务的 bootstrap.yml

spring:
  application:
    name: secondservice
eureka:
  instance:
    hostname: ${spring.application.name}
    preferIpAddress: true
    instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
    statusPageUrlPath: ${server.servlet.context-path}/actuator/info
    healthCheckUrlPath: ${server.servlet.context-path}/actuator/health
    leaseRenewalIntervalInSeconds: 15
    leaseExpirationDurationInSeconds: 45
    metadata-map:
      server.servlet.context-path: ${server.servlet.context-path}
  client:
    enabled: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka
Run Code Online (Sandbox Code Playgroud)

我的测试/模板服务的 bootstrap.yml

spring:
  application:
    name: templateservice
eureka:
  instance:
    hostname: ${spring.application.name}
    preferIpAddress: true
    instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}} …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot netflix-eureka spring-cloud-feign netflix-ribbon

6
推荐指数
1
解决办法
7490
查看次数

Spring Cloud OpenFeign 创建动态查询参数失败

Spring Cloud openFeign 无法创建动态查询参数。它抛出以下异常,因为 SpringMvcContract 试图找到不存在的 RequestParam 值属性。

java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0


@RequestMapping(method = RequestMethod.GET, value = "/orders")
Pageable<Order> searchOrder2(@RequestParam CustomObject customObject);
Run Code Online (Sandbox Code Playgroud)

我尝试使用@QueryMap而不是@RequestParam@QueryMap不生成查询参数。

顺便说一句,@RequestParam Map<String, Object> params方法参数可以很好地生成动态查询参数。

但我想使用一个自定义对象,其中 feign 客户端可以从对象的属性生成动态查询参数。

spring spring-mvc spring-boot spring-cloud spring-cloud-feign

6
推荐指数
2
解决办法
4470
查看次数

对假客户端的反应式支持

我计划使用 spring webflux 将我的微服务从阻塞实现重构为反应式 API。我有几个疑问:

1)是否选择基于注解的控制器或功能路由器?2) 是否支持反应式假装客户端?

请帮忙。

spring microservices spring-cloud spring-cloud-feign spring-webflux

6
推荐指数
2
解决办法
9383
查看次数

spring-cloud-starter-openfeign:无效的 HTTP 方法:PATCH 执行 PATCH

语境

我有一个 spring boot (version 2.2.6.RELEASE) web 项目。

从这个 Web 应用程序(我称之为“APP1”)我想使用来自另一个 Web 应用程序的 PATCH 方法调用另一个 URI(我们称之为“APP2”)。在我的 pom.xml 中,我有以下依赖项:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

下面是我如何调用其他 Web 应用程序的 PATCH 方法。

@FeignClient(name = "clientName", url = "base-uri")
public interface MyInterface{
   @PatchMapping(value = "/target-uri")
    void callClientMethod(Map<String, Object> args);
Run Code Online (Sandbox Code Playgroud)

问题

  • APP2 的 PATCH 方法被有效调用
  • 但随后 APP1 抛出以下错误:
    • feign.RetryableException:无效的 HTTP 方法:PATCH 正在执行 PATCH

我在互联网上寻找解决方案,并在我的 pom.xml 中添加了以下 snipet

<dependency>
    <groupId>com.netflix.feign</groupId> <!-- Also tried io.github.openfeign -->
    <artifactId>feign-httpclient</artifactId>
    <version>8.18.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

之后,APP2 的 PATCH 方法仍然被正确调用,但在 APP1 中我收到以下错误: java.lang.NoSuchMethodError: feign.Response.create (ILjava/lang/String;Ljava/util/Map;Lfeign/Response$Body;)假/响应;

题 …

http-patch spring-cloud-feign feign

6
推荐指数
3
解决办法
5387
查看次数

为单个 Feign 客户端禁用 Hystrix

我的 SpringBoot 应用程序启用了 Hystrix,并为某些 Feign 客户端定义了回退,其余客户端未定义。

现在,我想为尚未定义回退的那些禁用 Hystrix。因此,我按照 [第 7.4 段] https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign.html 中列出的步骤操作,即使用 vanilla Feign.Builder 创建单独的 Feign 配置. 但是,添加新的 @Bean Feign.Builder 会禁用我不想要的所有 Feign 客户端的 Hystrix 功能。如果我删除@Bean Feign.Builder,Hystrix 回退会像往常一样在 myhystrixclient 中启动。一个类似的问题在这里如何在多个假客户端之一中禁用 hystrix仍然是开放的。我究竟做错了什么?

public class MyFeignClientConfiguration {

@Bean
public FeignErrorDecoder feignErrorDecoder() {
    return new FeignErrorDecoder();
}

@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
    return Feign.builder();
}
}
Run Code Online (Sandbox Code Playgroud)

我的 Feign 客户端如下所示:

@FeignClient(name = "myregularclient", configuration = MyFeignClientConfiguration.class)
public interface MyRegularClient {
//my APIs here
}
Run Code Online (Sandbox Code Playgroud)

我的 Hystrix Feign 配置如下所示:

public class …
Run Code Online (Sandbox Code Playgroud)

java spring-boot hystrix spring-cloud-feign

6
推荐指数
1
解决办法
1414
查看次数

我可以动态创建 Feign Client 或创建具有不同名称的实例吗

我定义了一个 REST 接口,它具有不同的 Spring Boot 应用程序实现,使用不同的实现spring.application.namespring.application.name在我的业务中不能相同)。

如何只定义一个Feign Client,并且可以访问所有SpringBootApplication REST服务?

SpringBootApplication A(spring.application.name=A) 和 B(spring.application.name=) 有这个 RestService:

@RestController
@RequestMapping(value = "/${spring.application.name}")
public class FeignRestService {

    @Autowired
    Environment env;

    @RequestMapping(path = "/feign")
    public String feign() {
        return env.getProperty("server.port");
    }
}
Run Code Online (Sandbox Code Playgroud)

另一个 SpringBootApplication C:

@FeignClient(name="SpringApplication A or B")
public interface FeignClientService {

    @RequestMapping(path = "/feign")
    public String feign();
}
Run Code Online (Sandbox Code Playgroud)

在SpringBootApplication C中,我想使用FeignClientService来访问A和B。你有什么想法吗?

spring-boot spring-cloud-feign feign netflix-ribbon spring-cloud-netflix

5
推荐指数
1
解决办法
6811
查看次数