继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

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

大话西游666
关注TA
已关注
手记 209
粉丝 140
获赞 620

一、什么是API网关

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

二、网关的职责

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

三、surging的网关架构设计

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

四、surging的网关使用

  1.配置

  https://img3.mukewang.com/5b3611530001220105330275.jpg

  在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": true12   },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.浏览网页(以下表示成功)

https://img4.mukewang.com/5b36115c0001290919130239.jpg

  5.请求token jwt模式(postman)

  Content-Type:application/json

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

 https://img3.mukewang.com/5b3611640001368e11270493.jpg

  如上图就表示token请求成功

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

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP