zoukankan      html  css  js  c++  java
  • (四)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请求成功

  • 相关阅读:
    [MyBatis]最简MyBatis工程
    eclipse中如何删除已经添加到 Web App Libraries 中引用的jar包
    day48_项目管理学习笔记
    项目流程之失败的案例
    项目流程之婚礼流程
    day47_Maven学习笔记
    快还要更快,让PHP 7 运行更加神速
    Linux服务器时间同步
    Win10系统开启Linux Bash命令行
    红帽RHOP 8 发布一条龙方案
  • 原文地址:https://www.cnblogs.com/alangur/p/9141555.html
Copyright © 2011-2022 走看看