• Ocelot 负载均衡


    Ocelot 负载均衡

    以上文中项目为例:https://www.cnblogs.com/1285026182YUAN/p/15234331.html

     1. 在OService1与OService2中 都增加以下控制器接口

    namespace OService1.Controllers
    {
        [Route("api/[controller]")]
        [ApiController]
        public class TeaController : ControllerBase
        {
            [Route("GetList")]
            [HttpGet]
            public IActionResult GetList()
            {
                return new JsonResult(new { name = "tea", Host = HttpContext.Request.Host.Value });
            }
        }
    }

     访问接口:

    https://localhost:6001/api/tea/getlist
    https://localhost:6002/api/tea/getlist

    2. 修改 OService.json文件配置

    {
      "Routes": [
        //路由一
        {
          "DownstreamPathTemplate": "/api/Tea/GetList", //下游路径
          "DownstreamScheme": "https", //http,https
          "DownstreamHostAndPorts": [
            {
              "Host": "localhost", //下游地址
              "Port": 6001 //下游端口
            },
            {
              "Host": "localhost", //下游地址
              "Port": 6002 //下游端口
            }
          ],
          "UpstreamPathTemplate": "/ocelot/GetTea", //上游路径
          "UpstreamHttpMethod": [ "Get" ],
          "LoadBalancerOptions": { "Type": "RoundRobin" } //轮询
        }
      ],
      "GlobalConfiguration": {
        "BaseUrl": "https://localhost:5001"
      }
    }

    访问地址:

    https://localhost:5001/ocelot/gettea

    测试: 

    LeadConnection负载均衡器算法共有4种:

    • LeastConnection 把新请求发送到现有请求最少的服务上

    • RoundRobin 轮询可用的服务并发送请求

    • NoLoadBalancer 不负载均衡,总是发往第一个可用的下游服务

    • CookieStickySessions 使用cookie关联所有相关的请求到制定的服务

    参考:http://letyouknow.net/ocelot/ocelot-tutorial-2.html
    项目:https://gitee.com/wuxincaicai/ocelothost.git

  • 相关阅读:
    NEO发行资产Token
    OSCP考试回顾
    Windows降权
    Mimikatz.ps1本地执行
    MS16-032提权正确方法
    一种通过HTTP传文件出网的姿势
    mac chromedriver error
    关于websocket 在生产环境中遇到的问题 及 解决办法
    how to install protobuff python
    Git 使用疑问
  • 原文地址:https://www.cnblogs.com/1285026182YUAN/p/15238452.html
Copyright © 2020-2023  润新知