[译]Ocelot - Load Balancer
可以对下游的服务进行负载均衡。
提供了下面几种负载均衡:
- LeastConnection - tracks which services are dealing with requests and sends new requests to service with least existing requests. The algorythm state is not distributed across a cluster of Ocelot’s.
- RoundRobin - loops through available services and sends requests. The algorythm state is not distributed across a cluster of Ocelot’s.
- NoLoadBalancer - takes the first available service from config or service discovery.
- CookieStickySessions - uses a cookie to stick all requests to a specific server. More info below.
必须要在配置你面指定你要使用的复杂均衡类型。
Configuration
下面的例子中一个ReRoute设置了多个下游服务,并且使用了LeastConnection负载均衡。这个是设置负载均衡最简单的方式。
{
"DownstreamPathTemplate": "/api/posts/{postId}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "10.0.1.10",
"Port": 5000,
},
{
"Host": "10.0.1.11",
"Port": 5000,
}
],
"UpstreamPathTemplate": "/posts/{postId}",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"UpstreamHttpMethod": [ "Put", "Delete" ]
}
Service Discovery
下面的例子通过service discovery provider设置ReRoute,并且使用了LeastConnection负载均衡:
{
"DownstreamPathTemplate": "/api/posts/{postId}",
"DownstreamScheme": "https",
"UpstreamPathTemplate": "/posts/{postId}",
"UpstreamHttpMethod": [ "Put" ],
"ServiceName": "product",
"LoadBalancerOptions": {
"Type": "LeastConnection"
},
"UseServiceDiscovery": true
}
CookieStickySessions
这个是为了解决有了负载均衡,但是没有独立session state服务器造成的问题而出现的。
配置如下:
{
"DownstreamPathTemplate": "/api/posts/{postId}",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{
"Host": "10.0.1.10",
"Port": 5000,
},
{
"Host": "10.0.1.11",
"Port": 5000,
}
],
"UpstreamPathTemplate": "/posts/{postId}",
"LoadBalancerOptions": {
"Type": "CookieStickySessions",
"Key": "ASP.NET_SessionId",
"Expiry": 1800000
},
"UpstreamHttpMethod": [ "Put", "Delete" ]
}
Type要设置为CookieStickySessions, Key是session对应的cookie名,Expiry设置过期,单位为毫秒 。
If you have multiple ReRoutes with the same LoadBalancerOptions then all of those ReRoutes will use the same load balancer for there subsequent requests. This means the sessions will be stuck across ReRoutes.
Please note that if you give more than one DownstreamHostAndPort or you are using a Service Discovery provider such as Consul and this returns more than one service then CookieStickySessions uses round robin to select the next server. This is hard coded at the moment but could be changed.
[译]Ocelot - Load Balancer的更多相关文章
- 负载均衡server load balancer
负载均衡(Server Load Balancer,简称SLB)是对多台云服务器进行流量分发的负载均衡服务.SLB可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性. ( ...
- Feign报错Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client
问题描述 使用Feign调用微服务接口报错,如下: java.lang.RuntimeException: com.netflix.client.ClientException: Load balan ...
- Load balancer does not have available server for client
最近在研究spring-cloud,研究zuul组件时发生下列错误: Caused by: com.netflix.client.ClientException: Load balancer does ...
- Data Center手册(3): Load Balancer
Load Balancer的类型 DNS Round-Robin 这是一种很常见的分流的方式,具体配置如下: name server有一个zone文件,对于同一个domain,有多个IP www.ex ...
- CentOS7+CDH5.14.0安装CDH错误排查:Hue错误: Load Balancer 该角色的进程启动失败
Hue错误: Load Balancer 该角色的进程启动失败 解决办法:主机能够联网情况下,直接运行如下命令即可在线安装openssl.httpd 需要提前安装环境 httpd, mod_ssl ...
- NGINX Load Balancing - HTTP Load Balancer
This chapter describes how to use NGINX and NGINX Plus as a load balancer. Overview Load balancing a ...
- Azure Load Balancer : 动态扩展
笔者在前文<Azure Load Balancer : 支持 IPv6>中介绍了如何通过 PowerShell 脚本创建支持 IPv6 的 Load Balancer.本文我们接着介绍如何 ...
- Docker : Tomcat Clustering with Load Balancer (Tomcat and Nginx)
Tomcat Clustering Series Part 5 : NginX as Load Balancer - Ramki Technical Bloghttps://www.ramkitech ...
- com.netflix.client.ClientException: Load balancer does not have available server for client xxxx
版本 spring boot: 2.0.1.RELEASE spring cloud: Finchley.M9 错误 通过zuul调用eureka注册的服务,错误内容如下 Caused by: com ...
随机推荐
- Django REST framework基础:序列化
表结构: class Article(models.Model): id = models.AutoField(primary_key=True) title = models.CharField(m ...
- SQL数据库一些系统语法含义
昨天在数据库中建立数据表的时候要求显示的添加一些系统语法规则,对于这些设置不知道都是什么含义,这次记录下来供以后学习. (1)SET ANSI_NULLS ON语句 T-SQL支持在与空值进行比较时, ...
- he
弄好这个网站---to thi tha think 好这个---, 很温馨 那时候我还在看. 前一段时候看yibenhaoshu,走出来的才是理性,所以现在才是理性的看待的. 回头再看看两年前的事情, ...
- 【转】Android中保持Service的存活
这几天一直在准备考试,总算有个半天时间可以休息下,写写博客. 如何让Service keep alive是一个很常见的问题. 在APP开发过程中,需要Service持续提供服务的应用场景太多了,比如闹 ...
- wxWidgets 和 QT 之间的选择
(非原创,网络摘抄) 跨平台的C++ GUI工具库很多,可是应用广泛的也就那么几个,Qt.wxWidgets便是其中的翘楚这里把GTK+排除在外,以C实现面向对象,上手相当困难,而且Windows平台 ...
- c# winform 多屏显示
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- SpringCloud(1)服务注册与发现Eureka
1.创建1个空白的工程 2.创建2个model工程 一个module(即SpringBoot)工程作为服务注册中心,即Eureka Server,另一个作为Eureka Client. Eureka ...
- Entity Framework Core系列之DbContext(添加)
上一篇我们介绍了Entity Framework Core系列之DbContext,对DbContext有了概念上的了解,这篇将介绍DbContext添加数据 通过DbContext添加实体的主要方法 ...
- Maven将远程包拉去到项目指定路径
<build> <plugins> <plugin> <artifactId>maven-dependency-plugin</artifactI ...
- RecyclerView的点击、滑动、拖动事件
效果图: 在gradle里导包 implementation 'com.android.support:recyclerview-v7:28.0.0' activity_main <?xml ...