我正在寻找一种能够在API网关中提供各种数据聚合的解决方案.我使用spring cloud netflix zuul作为API网关.我使用弹簧靴创建了3个微服务 -
Catalog - All products
DeviceInfo - a particular product detail
Inventory - product stock
Run Code Online (Sandbox Code Playgroud)
这是Zuul配置 -
zuul.routes.deviceInfo.path=/device/deviceInfo/**
zuul.routes.deviceInfo.url=http://localhost:9002/getDeviceInfo
zuul.routes.catalog.path=/device/all/**
zuul.routes.catalog.url=http://localhost:9001/getProductCatalog
zuul.routes.inventory.path=/device/stock/**
zuul.routes.inventory.url=http://localhost:9003/getInventory
ribbon.eureka.enabled=false
server.port=8080
Run Code Online (Sandbox Code Playgroud)
在产品详细信息页面中,我需要拨两个电话 -
http://localhost:8080/device/deviceInfo/ - for product details
http://localhost:8080/device/stock/ - for stock details
Run Code Online (Sandbox Code Playgroud)
有没有办法对API网关进行一次调用,它将结合上述两个调用的结果?两个调用都给出了JSON作为响应.
我正在使用Spring Cloud Config Server并能够检测来自git存储库的更改并将其传递给Config客户端.
有两种方法,我已经实现了它:
参考:http: //tech.asimio.net/2017/02/02/Refreshable-Configuration-using-Spring-Cloud-Config-Server-Spring-Cloud-Bus-RabbitMQ-and-Git.html
参考:https://spring.io/guides/gs/centralized-configuration/
所以两者都运行良好,那么使用Spring Cloud Bus是否有任何优势,或者在生产环境中,没有Spring Cloud Bus会有任何问题吗?因为在生产中将RabbitMQ集群(HA)设置为Spring Cloud Bus需要额外的努力.
谢谢,大卫
spring-boot spring-cloud spring-cloud-netflix spring-cloud-config
在我的应用程序中,我需要调用外部端点,如果速度太慢,则会激活回退.
以下代码是我的应用程序的示例:
@FeignClient(name = "${config.name}", url = "${config.url:}", fallback = ExampleFallback.class)
public interface Example {
@RequestMapping(method = RequestMethod.GET, value = "/endpoint", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
MyReturnObject find(@RequestParam("myParam") String myParam);
}
Run Code Online (Sandbox Code Playgroud)
它的后备实施:
@Component
public Class ExampleFallback implements Example {
private final FallbackService fallback;
@Autowired
public ExampleFallback(final FallbackService fallback) {
this.fallback = fallback;
}
@Override
public MyReturnObject find(final String myParam) {
return fallback.find(myParam);
}
Run Code Online (Sandbox Code Playgroud)
此外,配置的断路器超时:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
如何实现集成测试以检查我的电路中断是否正常工作,即,如果我的端点(在这种情况下是模拟的)很慢或者它是否返回了像4xx或5xx这样的错误?
我正在使用带有Spring Cloud的Spring Boot 1.5.3(Feign + Hystrix)
testing spring-boot hystrix spring-cloud-feign spring-cloud-netflix
我正在使用具有功能端点的Spring WebFlux来创建API.为了提供我想要的结果,我需要使用外部RESTful API,并以异步方式执行此操作,我正在使用WebClient实现.效果很好,就像这样:
public WeatherWebClient() {
this.weatherWebClient = WebClient.create("http://api.openweathermap.org/data/2.5/weather");
}
public Mono<WeatherApiResponse> getWeatherByCityName(String cityName) {
return weatherWebClient
.get()
.uri(uriBuilder -> uriBuilder
.queryParam("q", cityName)
.queryParam("units", "metric")
.queryParam("appid", API_KEY)
.build())
.accept(APPLICATION_JSON)
.retrieve()
.bodyToMono(WeatherApiResponse.class);
}
Run Code Online (Sandbox Code Playgroud)
由于这会执行网络访问,因此它是NetFlix OSS Hystrix的一个很好的用例.我已经尝试过使用spring-cloud-starter-netflix-hystrix,将@HystrixCommand添加到上面的方法中,但即使我设置了错误的URL(404)或错误的API_KEY(401),也无法使其跳闸. .
我认为这可能是与WebFlux本身兼容的问题,但设置属性@HystrixProperty(name ="circuitBreaker.forceOpen",value ="true")确实迫使回退方法运行.
我错过了什么吗?这种方法是否与Spring WebClients不兼容?
谢谢!
我有一个 Spring 启动应用程序,它使用 Feign 通过 Eureka 调用外部 Web 服务。我希望能够使用 Feign 接口的模拟实现来运行应用程序,这样我就可以在本地运行应用程序,而不必运行 Eureka 或外部 Web 服务。我曾想过定义一个允许我这样做的运行配置,但我正在努力让它工作。问题是,无论我尝试什么,Spring 的“魔法”都会为 Feign 接口定义一个 bean。
Feign 接口
@FeignClient(name = "http://foo-service")
public interface FooResource {
@RequestMapping(value = "/doSomething", method = GET)
String getResponse();
}
Run Code Online (Sandbox Code Playgroud)
服务
public class MyService {
private FooResource fooResource;
...
public void getFoo() {
String response = this.fooResource.getResponse();
...
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试添加一个配置类,如果 Spring 配置文件是“本地”,则该配置类有条件地注册了一个 bean,但是当我使用该 Spring 配置文件运行应用程序时,它从未被调用过:
@Configuration
public class AppConfig {
@Bean
@ConditionalOnProperty(prefix = "spring.profile", name = "active", havingValue="local")
public FooResource fooResource() { …Run Code Online (Sandbox Code Playgroud) spring-boot netflix-feign spring-cloud-feign spring-cloud-netflix
只是想澄清一下 - 在 Netflix 的 Zuul 网关中,RequestContext 对象有两个方法,setSendZuulResponse 和 removeRouteHost。
首先,谁能告诉我两者之间的区别。从这篇文章中,他们做了同样的事情,但我找不到描述这些的文档(sendZuulResponse和removeRouteHost)。
其次,Zuul 过滤器是否命中了资源/源服务器而不管是否被过滤但只是隐藏了对客户端的响应?根据sendZuulResponse的文档,它说:
"If this value if true then the response should be sent to the client."
Run Code Online (Sandbox Code Playgroud)
我的理由是,如果此值设置为 false,则不应*将响应发送给客户端;然而,Zuul 有响应(???),这意味着它无论如何都发送了请求(如果这是有道理的)。
谢谢。
我在服务 A 和 B 前使用 Netflix Zuul 代理。
如何让 Zuul 代理根据传入请求中的 HTTP 标头在 A 和 B 的路由之间进行选择?
我在我的一个Spring启动应用程序中实现了Netflix OSS Hystrix.并为HystrixCommand配置了一些属性.但是,如何验证HystrixCommand是否真正使用了这些属性.例如,
hystrix.threadpool.default.maxQueueSize=12
hystrix.threadpool.default.keepAliveTimeMinute=2
hystrix.command.default.execution.isolation.strategy=SEMAPHORE
Run Code Online (Sandbox Code Playgroud)
如何才能看到这些属性应用于HystrixCommand?有什么办法可以为Hystrix启用调试级别日志记录吗?
TIA
是否可以将 Ribbon 和 Eureka 服务发现与 spring webflux webclient 一起使用?
我尝试了此代码,但在集成测试期间出现错误。
reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalArgumentException: URI 不是绝对的:/auth-service/auth-service/validate-manager-client-access
@Bean
@LoadBalanced
public WebClient loadBalancedWebClient() {
return WebClient.create(baseURL);
}
@Override
public Mono<Boolean> validateManagerClientAccess(Mono<LoginDTO> loginDTOMono) {
return webClient
.post()
.uri(validateManagerURL)
.body(loginDTOMono, LoginDTO.class)
.retrieve()
.bodyToMono(Boolean.class);
}
# Remote Services Configuration
remote:
auth-service:
service-id: auth-service
path:
validate-manager-client-access: /auth-service/validate-manager-client-access
Run Code Online (Sandbox Code Playgroud) spring spring-boot microservices spring-cloud-netflix reactive
在server-side负载平衡中,客户端调用中间服务器,然后决定调用实际服务器(或微服务)的哪个实例。
在client-side负载均衡中,客户端也会调用一个中间服务器(例如,API 网关——Zuul例如,配置了一个负载均衡器——Ribbon例如和一个命名服务器—— Eureka),然后它决定调用微服务的哪个实例。
除非我们将 API 网关作为客户端的一部分,否则客户端仍然不知道它应该将请求发送到的确切服务器的 IP 地址。在我看来,很像服务器端负载平衡。有什么我想念的吗?
(包括 API 网关作为客户端的一部分似乎很奇怪,因为它通常部署在与客户端不同的服务器上)
spring spring-boot microservices netflix-eureka spring-cloud-netflix
spring-boot ×7
hystrix ×3
netflix-zuul ×3
spring ×2
spring-cloud ×2
java ×1
netflix ×1
reactive ×1
testing ×1