我有许多客户端已经定义了"全局"RequestInterceptor.对于其中一个客户,我需要排除这个"全局"拦截器.是否可以覆盖特定FeignClient的完整RequestInterceptors集?
@FeignClient(value = "foo", configuration = FooClientConfig.class)
public interface FooClient {
//operations
}
@Configuration
public class FooClientConfig{
//How do I exclude global interceptors from this client configuration?
}
Run Code Online (Sandbox Code Playgroud)
使用的spring-cloud-netflix版本为1.1.0 M5
spring-cloud netflix-feign spring-cloud-feign feign spring-cloud-netflix
我在尝试生成Spring Feign客户端时收到错误:"方法有太多的Body参数"
@RequestMapping(value="/media", method=RequestMethod.POST)
String uploadMedia(@RequestHeader("Authentication") String token,
@RequestPart("media") MultipartFile audio,
@RequestPart("a-json-object") SomeClass someClazz,
@RequestPart("another-json-object") AnotherClass anotherClazz);
Run Code Online (Sandbox Code Playgroud)
我找到了以下解决方案,它在使用常规Feign注释时有效,但在Spring MVC注释时无效:
无法让Feign客户工作。首先尝试使用POST。保持与编码器/解码器有关的错误,指出类型不正确。然后在github上找到一个示例来最终调用简单的GET API,并决定尝试一下。仍然失败
在Github和在线上,我看到Feign Client Spring-Cloud,OpenFeign,Netflix.feign的多个版本具有不同的版本。谁能形容一个最好的,稳定的Feign客户应该用于生产什么?
package com.paa.controllers;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient (name="test-service",url="https://www.reddit.com/r")
public interface GetFeignClient {
@RequestMapping(method = RequestMethod.GET, value = "/java.json")
public String posts();
}
Controller:
@RestController
@RequestMapping("/some/api")
public class TestWLCController {
@Autowired
private GetFeignClient getFeignClient;
.. some stuff
@RequestMapping(value="/postSomething",method = RequestMethod.POST)
@ApiOperation(value = "Configures something",
notes = "basic rest controller for testing feign")
public ResponseEntity<SomeResponse> feignPost(
UriComponentsBuilder builder,
@ApiParam(name = "myRequest",
value = "request for configuring something",
required = true)
@Valid @RequestBody SomeRequest someRequest) { …Run Code Online (Sandbox Code Playgroud) 我有一个使用 3 个假客户端的服务。每次启动应用程序时,我都会在第一次调用任何 feign 客户端时收到 TimeoutException。
在一切稳定之前,我必须至少触发每个假客户端一次。在网上环顾四周,问题在于 feign 或 hystrix 内部的某些内容是延迟加载的,解决方案是创建一个覆盖 spring 默认值的配置类。我已经用下面的代码试过了,但它仍然没有帮助。我仍然看到同样的问题。任何人都知道解决这个问题?是通过 hystrix 回调两次调用 feignclient 的唯一解决方案吗?
@FeignClient(value = "SERVICE-NAME", configuration =ServiceFeignConfiguration.class)
@Configuration
public class ServiceFeignConfiguration {
@Value("${service.feign.connectTimeout:60000}")
private int connectTimeout;
@Value("${service.feign.readTimeOut:60000}")
private int readTimeout;
@Bean
public Request.Options options() {
return new Request.Options(connectTimeout, readTimeout);
}
}
Run Code Online (Sandbox Code Playgroud)
Spring Cloud - Brixton.SR4 Spring Boot - 1.4.0.RELEASE
这一切都在 docker Ubuntu - 12.04 Docker - 1.12.1 Docker-Compose - 1.8 中运行
我们在带有Docker的AWS ECS上部署了微服务架构。API网关和Eureka来自Spring。我们有Java / NodeJS微服务,可以通过网关正常运行,但是使用SteelToe Eureka客户端的.NET微服务为我们提供了连接重置异常。
以下是屏幕截图,可帮助您更好地理解。
我们花了很多时间试图解决这个问题,但是目前还没有成功。我们可以得到一些帮助来解决这个问题。
非常感谢你!
我问自己一个问题而没有找到答案.也许有人在这里会有想法;-)在Spring Cloud中使用RestTemplate和Feign客户端的服务注册表(Eureka),我有相同服务的不同构建版本.构建版本通过Actuator的/ info端点进行记录.
{
"build": {
"version": "0.0.1-SNAPSHOT",
"artifact": "service-a",
"name": "service-a",
"group": "com.mycompany",
"time": 1487253409000
}
}
...
{
"build": {
"version": "0.0.2-SNAPSHOT",
"artifact": "service-a",
"name": "service-a",
"group": "com.mycompany",
"time": 1487325340000
}
}
Run Code Online (Sandbox Code Playgroud)
在客户的电话中有任何意思要求特定的构建版本吗?我应该使用网关的路由过滤器来管理吗?但是我觉得版本检测仍然是一个问题......
好吧,任何建议都表示赞赏.
@FeignClient(name ="test",url ="http:// xxxx")
如何在运行时更改feign url(url ="http:// xxxx")?因为网址只能在运行时确定.
有假装客户介绍:
@FeignClient(name = "storeClient", url = "${feign.url}")
public interface StoreClient {
//..
}
Run Code Online (Sandbox Code Playgroud)
是否可以利用环境更改的Spring Cloud功能在运行时更改Feign url?(更改feign.url属性并调用/refresh端点)
我正在使用混合 Spring-Cloud + feign + spring-retry 来帮助在客户端重试请求(都是基于 Kotlin 的后端)
我的 spring-boot conf 是这样的:
myApp:
ribbon:
OkToRetryOnAllOperations: true
retryableStatusCodes: 404, 503
Run Code Online (Sandbox Code Playgroud)
(注意:OkToRetryOnAllOperations=true 仅用于重试 POST/PUT 请求)
重试 404 和 503 HTTP 代码听起来不错,但我不知道是否有要重试的“经典”或“默认”错误代码列表。这种好的做法存在吗?
我们假设所有请求在服务器端都是幂等的(如果不是,重试可能会导致问题)。
我尝试将Springboot 1.xy(Brussels-SR12)迁移到我使用的2.xy FeignClients
我更改Maven配置:
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
Run Code Online (Sandbox Code Playgroud)
所以
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign</artifactId>
<version>2.0.0.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)
我更改所有导入:
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignClient;
Run Code Online (Sandbox Code Playgroud)
至
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
Run Code Online (Sandbox Code Playgroud)
我使用此接口:
@FeignClient(value = "COMPANY", fallbackFactory = CompanyClientFallbackFactory.class, configuration = FeignConfiguration.class)
public interface CompanyClient extends CompanyApi {
}
Run Code Online (Sandbox Code Playgroud)
当我运行JUnit测试(使用spring上下文)时,我现在遇到此错误(不在Springboot 1.xy和旧的netflix包中):
The bean 'COMPANY.FeignClientSpecification', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
Run Code Online (Sandbox Code Playgroud)
完整跟踪:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.postProcessFields(MockitoTestExecutionListener.java:99)
at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.injectFields(MockitoTestExecutionListener.java:79)
at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.prepareTestInstance(MockitoTestExecutionListener.java:54)
at …Run Code Online (Sandbox Code Playgroud) spring-cloud ×6
spring ×3
spring-boot ×3
feign ×2
hystrix ×1
java ×1
kotlin ×1
rest ×1
spring-retry ×1