![](/img/trans.png)
[英]How do I use the ConsulDiscoveryClient with Zuul and Sidecar in Spring-Cloud
[英]How to get spring-cloud zuul to use a different circuit for different services
我正在尝试使用spring-cloud-starter-zuul。 我已经安装了Eureka,并注册了作为Eureka客户编写的简单服务。 我在两个具有不同应用程序名称的不同主机上注册了两个实例,因此它们是Eureka中的两个不同服务。 我的目标是确保如果serviceA表现良好而serviceB表现不佳,则对serviceA的代理不会受到对serviceB代理失败的影响。
如果我通过zuul单独运行负载测试serviceA,那么我可以毫无问题地保持400 TPS的吞吐量。 如果我随后抛出serviceB并使其完全过载并使它到处超时,我希望serviceA在400时会继续运行,而serviceB会陷入困境,但相反,serviceA的成功率会降至50 TPS以下,并且会有很多错误好。
看来RibbonRoutingFilter产生的所有RibbonCommands在hystrix中共享相同的电路,这对我来说毫无意义。 在它创建RibbonCommand的RibbonRoutingFilter中,我看不到有任何方法可以配置它以使用其他命令。
在RibbonRoutingFilter中:
RibbonCommand command = new RibbonCommand(restClient, verb, uri,
convertHeaders(headers), convertHeaders(params), requestEntity);
我已经验证了restClient对于serviceA和serviceB是不同的,因此它们使用的是我在application.yml文件中指定的连接池配置,但是serviceA和serviceB之间在服务质量方面仍然存在大量交叉污染服务B.
RibbonCommand似乎有另一个构造函数,该构造函数将“ commandKey”作为第一个参数,而我引用的构造函数只是将commandKey值为“ default”委派给该构造函数。 我在RibbonRoutingFilter中看不到任何可替代它的选项或选项。 对我来说,这在从spring-cloud项目中使用时严重损害了Zuul的生存能力。
我有没有一种方法可以立即配置它,以便每个服务都有自己的电路?
pom的适用部分:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>1.0.0.RC1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
application.yml:
ribbon:
ConnectTimeout: 5000
ReadTimeout: 5000
MaxAutoRetries: 0
MaxAutoRetriesNextServer: 0
OkToRetryOnAllOperations: false
MaxHttpConnectionsPerHost: 200
MaxTotalHttpConnections: 1000
echo1:
ribbon:
ActiveConnectionsLimit: 200
echo2:
ribbon:
ActiveConnectionsLimit: 400
spring:
application:
name: SpringCloudProxywall
server:
port: 8080
zuul:
routes:
echo1:
path: /echo1/**
serviceId: echo1
stripPrefix: false
echo2:
path: /echo2/**
serviceId: echo2
stripPrefix: false
我的应用程序类:
@Configuration
@ComponentScan
//@EnableCircuitBreaker <-- is already included in EnableZuulProxy
@EnableZuulProxy
@EnableTurbine
@EnableHystrixDashboard
@EnableAutoConfiguration
public class SpringCloudProxywallApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudProxywallApplication.class, args);
}
}
我认为,如果您使用的快照已经是默认快照(每个后端使用不同的电路): https : //github.com/spring-cloud/spring-cloud-netflix/issues/160 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.