• (四)surging 微服务框架使用系列之网关


    一、什么是API网关

      API网关是一个服务器,是系统对外的唯一入口。API网关封装了系统内部架构,为每个客户端提供一个定制的API。API网关方式的核心要点是,所有的客户端和消费端都通过统一的网关接入微服务,在网关层处理所有的非业务功能。通常,网关也是提供REST/HTTP的访问API。服务端通过API-GW注册和管理服务。

    二、网关的职责

      网关具有的职责,如身份验证、监控、负载均衡、缓存、请求分片与管理、静态响应处理。当然,最主要的职责还是与“外界联系”。

    三、surging的网关架构设计

      https://www.cnblogs.com/fanliang11/p/7441281.html

    四、surging的网关使用

      1.配置

      

      在surging网关的configs文件下有三个配置。appsettings:自定义的配置。cacheSettings:缓存的配置。gatewaySettings:网关配置。

      gatewaySettings 配置:

     1 {
     2   "AccessTokenExpireTimeSpan": "30",//token过期时间,单位分钟
     3   "AuthorizationRoutePath": "api/userapp/authentication",//token服务验证方法
     4   "AuthorizationServiceKey": "UserApp",//服务对应的ModuleName
     5   "TokenEndpointPath": "api/oauth2/token",//token请求对外路径
     6   "CacheMode": "ddlCache.Redis", //MemoryCache or  gateway.Redis save token(缓存配置)
     7   //跨域配置
     8   "AccessPolicy": {
     9     "Origins": [ "http://127.0.0.1:1927", "http://localhost:927" ],
    10     "AllowAnyHeader": true,
    11     "AllowAnyMethod": true
    12   },
    13   //注册中心配置(zookeeper或者consul)
    14   "Register": {
    15     "Provider": "Consul",
    16     "Address": "127.0.0.1:8500"
    17   },
    18   //服务聚合配置
    19   "ServicePart": {
    20     "MainPath": "part/service/aggregation",
    21     "EnableAuthorization": false,
    22     "Services": [
    23       {
    24         "ServiceAggregation": [
    25           {
    26             "RoutePath": "api/user/GetUserName",
    27             "ServiceKey": "User",
    28             "Key": "Users"
    29           },
    30           {
    31             "RoutePath": "api/user/GetUserName",
    32             "ServiceKey": "User",
    33             "Key": "Roles"
    34           }
    35         ],
    36         "UrlMapping": "part/user/getuserrole"
    37       }
    38     ]
    39   }
    40 }

      2.将网关发布。

      3.将服务启动

      4.浏览网页(以下表示成功)

      5.请求token jwt模式(postman)

      Content-Type:application/json

      请求参数:input 是api/userapp/authentication方法对应的参数名称。里面的对象是你真正的要传的参数对象

     

      如上图就表示token请求成功

  • 相关阅读:
    Framework 4.0 新关键字dynamic 之我见(二)
    随便歇歇
    最近的一些总结
    一周最新示例代码回顾 (7/16 7/22)
    一周最新示例代码回顾 (5/28–6/3)
    一周最新示例代码回顾 (5/14–5/20)
    一周最新示例代码回顾 (6/25 7/1)
    微软一站式示例代码浏览器本周更新发布
    一周最新示例代码回顾 (6/11 6/17)
    示例代码浏览器5.4功能更新
  • 原文地址:https://www.cnblogs.com/alangur/p/9141555.html
Copyright © 2020-2023  润新知