原文

可以对下游的服务进行负载均衡。

提供了下面几种负载均衡:

  • 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要设置为CookieStickySessionsKey是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的更多相关文章

  1. 负载均衡server load balancer

    负载均衡(Server Load Balancer,简称SLB)是对多台云服务器进行流量分发的负载均衡服务.SLB可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性. ( ...

  2. 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 ...

  3. Load balancer does not have available server for client

    最近在研究spring-cloud,研究zuul组件时发生下列错误: Caused by: com.netflix.client.ClientException: Load balancer does ...

  4. Data Center手册(3): Load Balancer

    Load Balancer的类型 DNS Round-Robin 这是一种很常见的分流的方式,具体配置如下: name server有一个zone文件,对于同一个domain,有多个IP www.ex ...

  5. CentOS7+CDH5.14.0安装CDH错误排查:Hue错误: Load Balancer 该角色的进程启动失败

    Hue错误: Load Balancer 该角色的进程启动失败 解决办法:主机能够联网情况下,直接运行如下命令即可在线安装openssl.httpd 需要提前安装环境  httpd, mod_ssl ...

  6. NGINX Load Balancing - HTTP Load Balancer

    This chapter describes how to use NGINX and NGINX Plus as a load balancer. Overview Load balancing a ...

  7. Azure Load Balancer : 动态扩展

    笔者在前文<Azure Load Balancer : 支持 IPv6>中介绍了如何通过 PowerShell 脚本创建支持 IPv6 的 Load Balancer.本文我们接着介绍如何 ...

  8. Docker : Tomcat Clustering with Load Balancer (Tomcat and Nginx)

    Tomcat Clustering Series Part 5 : NginX as Load Balancer - Ramki Technical Bloghttps://www.ramkitech ...

  9. 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 ...

随机推荐

  1. 基于tcp的云盘上传下载的模拟

    老师的博客: server端 import json import struct import json import struct import socket import os sk = sock ...

  2. 解决 tomcat 重启上传文件消失

    开发模式 首先开发者模式下,部署在 Tomcat 上没有什么好的办法,否则无法调试 除非使用绝对路径,缺点:不同的操作系统路径不同,自动设置 对于图片上传一般我们使用图片服务器,上传 CDN中 一般获 ...

  3. koa2--delegates模块源码解读

    delegates模块是由TJ大神写的,该模块的作用是将内部对象上的变量或函数委托到外部对象上.然后我们就可以使用外部对象就能获取内部对象上的变量或函数.delegates委托方式有如下: gette ...

  4. UITouch - BNR

    本节任务:创建一个视图,让用户在视图上拖动手指来画线. UIView类能够重载4个方法来处理不同的触摸事件. - (void)touchesBegan:(NSSet *)touches withEve ...

  5. Elasticsearch通关教程(五):如何通过SQL查询Elasticsearch

    前言 这篇博文本来是想放在全系列的大概第五.六篇的时候再讲的,毕竟查询是在索引创建.索引文档数据生成和一些基本概念介绍完之后才需要的.当前面的一些知识概念全都讲解完之后再讲解查询是最好的,但是最近公司 ...

  6. 图表插件Highcharts的动态化赋值,实现图表数据的动态化设置显示

    在很早之前就介绍过图表插件Highcharts的使用了,在2014年的随笔<基于MVC4+EasyUI的Web开发框架经验总结(4)--使用图表控件Highcharts>,这里基本上都介绍 ...

  7. asp.net core 2.1认证

    asp.net core 2.1认证 这篇文章基于asp.net core的CookieAuthenticationHandler来讲述. 认证和授权很相似,他们的英文也很相似,一个是Authenti ...

  8. Python可变参数*和**

    可变参数 在Python函数中,还可以定义可变参数.顾名思义,可变参数就是传入的参数个数是可变的,可以是1个.2个到任意个,还可以是0个. 我们以数学题为例子,给定一组数字a,b,c……,请计算a2 ...

  9. SpringCloud学习笔记:熔断器Hystrix(5)

    1. Hystrix简介 在分布式系统中,服务与服务之间相互依赖,一种不可避免的情况是某些服务会出现故障,导致依赖于它们的其他服务出现远程调度的线程阻塞. Hystrix提供熔断器功能,能够阻止分布式 ...

  10. Tampermonkey-让百度云下载飞起来

    1. 简介Tampermonkey是一款免费的浏览器扩展程序. 我们这里用于谷歌浏览器,目的是为了让百度云里面的文件以满速下载,节约金钱. 2. 安装安装Lantern蓝灯或者其他的FQ工具. 打开F ...