如何通过功能区(非假设)对微服务进行负载均衡。我有3个微服务" M1"," M2"和" M2_duplication"," M1"正在与" M2"通过假装。我想要" M2"获得太多流量,请求将被转发到" M2_duplication"。这怎么可能通过@ribbonclient?
POM M1:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
M1中的假装电话:
//name is taken from Eureka(service registry)
@FeignClient(name = "M1")
public interface M1ServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/getAllM2")
Map<String, String> getAllM2();
}
申请M1:
@EnableConfigurationProperties()
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class PortefeuilleApplication {
public static void main(String[] args) {
SpringApplication.run(PortefeuilleApplication.class, args);
}
}
答案 0 :(得分:2)
你的问题相当含糊......例如,你明确表示'不假装',然后展示FeignClient。不过,您似乎在询问如何为功能区负载均衡器实现可用性模式。为此,您需要创建功能区配置类,然后覆盖负载均衡器策略规则。例如:
@Configuration
public class MyConfiguration {
@Bean
public IRule ribbonRule() {
return new RoundRobinRule();
}
}
围绕可用性存在许多现有的功能区规则策略,例如AvailabilityFilteringRule或BestAvailableFilter,但如果这些都不合适,您也可以编写自己的规则。完成课程后,修改RibbonClient注释以引用它,例如:
@RibbonClient(name = "myClient", configuration = MyConfiguration.class)
您可以在此处找到更多信息:https://github.com/Netflix/ribbon/wiki/Working-with-load-balancers