当前位置: 首页 > news >正文

做水印的网站免费网络推广

做水印的网站,免费网络推广,wordpress账号注册,做网站具体流程系列文章目录 1、.Net Core微服务入门系列(一)——项目搭建 2、.Net Core微服务入门全纪录(二)——Consul-服务注册与发现(上) 3、.Net Core微服务入门全纪录(三)——Consul-服务注…

系列文章目录

1、.Net Core微服务入门系列(一)——项目搭建
2、.Net Core微服务入门全纪录(二)——Consul-服务注册与发现(上)
3、.Net Core微服务入门全纪录(三)——Consul-服务注册与发现(下)
4、.Net Core微服务入门全纪录(四)——Ocelot-API网关(上)
5、.Net Core微服务入门全纪录(五)——Ocelot-API网关(下)
6、.Net Core微服务入门全纪录(六)——EventBus-事件总线
7、.Net Core微服务入门全纪录(七)——IdentityServer4-授权认证
8、.Net Core微服务入门全纪录(八)——Docker Compose与容器网络


在这里插入图片描述

文章目录

  • 系列文章目录
  • 前言📃
  • 一、服务发现
  • 二、服务治理
    • 2.1 缓存
    • 2.2 限流
    • 2.3 超时/熔断
  • 三、总结


前言📃

关于 微服务 的概念解释网上有很多, 个人理解微服务是一种系统架构模式,它和语言无关,和框架无关,和工具无关,和服务器环境无关。

微服务思想 是将传统的单体系统按照业务拆分成多个职责单一、且可独立运行的接口服务。至于服务如何拆分,没有明确的定义。几乎任何后端语言都能做微服务开发。微服务也并不是完美无缺的,微服务架构会带来更多的问题,增加系统的复杂度,引入更多的技术栈。

上一篇【.Net Core微服务入门全纪录(四)——Ocelot-API网关(上)】已经完成了Ocelot网关的基本搭建,实现了服务入口的统一。当然,这只是API网关的一个最基本功能,它的进阶功能还有很多很多。

一、服务发现

首先需要解决的就是服务发现的问题,服务发现的优点之前讲过,就不说了。

上一篇中我们的服务地址都是写在 ocelot.json 配置文件里,现在我们需要结合之前的 Consul来实现服务发现。

改造代码:
首先 NuGet 安装 Ocelot.Provider.Consul

在这里插入图片描述
修改 Startup.cs

        public void ConfigureServices(IServiceCollection services){//添加ocelot服务services.AddOcelot().AddConsul();//添加consul支持}

修改 ocelot.json 配置:

{"Routes": [{"DownstreamPathTemplate": "/products","DownstreamScheme": "http","UpstreamPathTemplate": "/products","UpstreamHttpMethod": [ "Get" ],"ServiceName": "ProductService","LoadBalancerOptions": {"Type": "RoundRobin"}},{"DownstreamPathTemplate": "/orders","DownstreamScheme": "http","UpstreamPathTemplate": "/orders","UpstreamHttpMethod": [ "Get" ],"ServiceName": "OrderService","LoadBalancerOptions": {"Type": "RoundRobin"}}],"GlobalConfiguration": {"BaseUrl": "http://localhost:9070","ServiceDiscoveryProvider": {"Scheme": "http","Host": "localhost","Port": 8500,"Type": "Consul"}}
}

这个配置应该很好理解,就是把我们上次的 DownstreamHostAndPorts 节点去掉了,然后增加了ServiceDiscoveryProvider 服务发现相关配置。

注意,Ocelot 除了支持 Consul 服务发现以外,还有 Eureka 也可以,Eureka 也是一个类似的注册中心。

好了,代码修改就差不多了,下面运行程序测试一下:

在这里插入图片描述
在这里插入图片描述
客户端正常运行。

至此我们就实现了服务注册与发现和api网关的基本功能。接下来就要提到:服务治理

二、服务治理

其实 服务治理 也没有一个非常明确的定义。它的作用简单来说,就是帮助我们更好的管理服务,提升服务的可用性。——缓存,限流,熔断,链路追踪 等等。。。都属于常用的服务治理手段。
之前讲的负载均衡,服务发现也可以算是服务治理。

2.1 缓存

Ocelot 中启用缓存,需要 NuGet 安装一下 Ocelot.Cache.CacheManager

在这里插入图片描述
修改 Startup.cs 中的 ConfigureServices() 方法:

//添加ocelot服务
services.AddOcelot()//添加consul支持.AddConsul()//添加缓存.AddCacheManager(x =>{x.WithDictionaryHandle();});

修改 ocelot.json 配置文件:

{"Routes": [{"DownstreamPathTemplate": "/products","DownstreamScheme": "http","UpstreamPathTemplate": "/products","UpstreamHttpMethod": [ "Get" ],"ServiceName": "ProductService","LoadBalancerOptions": {"Type": "RoundRobin"},"FileCacheOptions": {"TtlSeconds": 5,"Region": "regionname"}},{"DownstreamPathTemplate": "/orders","DownstreamScheme": "http","UpstreamPathTemplate": "/orders","UpstreamHttpMethod": [ "Get" ],"ServiceName": "OrderService","LoadBalancerOptions": {"Type": "RoundRobin"},"FileCacheOptions": {"TtlSeconds": 5,"Region": "regionname"}}],"GlobalConfiguration": {"BaseUrl": "http://localhost:9070","ServiceDiscoveryProvider": {"Scheme": "http","Host": "localhost","Port": 8500,"Type": "Consul"}}
}

Routes 路由配置中增加了 FileCacheOptionsTtlSeconds 代表缓存的过期时间,Region 代表缓冲区名称,这个我们目前用不到。

好了,代码修改完需要编译重启一下网关项目,然后打开客户端网站测试一下:

在这里插入图片描述
可以看到,5秒之内的请求都是同样的缓存数据。Ocelot 也支持自定义缓存。

2.2 限流

限流就是限制客户端一定时间内的请求次数。

继续修改配置:

{"Routes": [{"DownstreamPathTemplate": "/products","DownstreamScheme": "http","UpstreamPathTemplate": "/products","UpstreamHttpMethod": [ "Get" ],"ServiceName": "ProductService","LoadBalancerOptions": {"Type": "RoundRobin"},"FileCacheOptions": {"TtlSeconds": 5,"Region": "regionname"},"RateLimitOptions": {"ClientWhitelist": [ "SuperClient" ],"EnableRateLimiting": true,"Period": "5s","PeriodTimespan": 2,"Limit": 1}},{"DownstreamPathTemplate": "/orders","DownstreamScheme": "http","UpstreamPathTemplate": "/orders","UpstreamHttpMethod": [ "Get" ],"ServiceName": "OrderService","LoadBalancerOptions": {"Type": "RoundRobin"},"FileCacheOptions": {"TtlSeconds": 5,"Region": "regionname"},"RateLimitOptions": {"ClientWhitelist": [ "SuperClient" ],"EnableRateLimiting": true,"Period": "5s","PeriodTimespan": 2,"Limit": 2}}],"GlobalConfiguration": {"BaseUrl": "http://localhost:9070","ServiceDiscoveryProvider": {"Scheme": "http","Host": "localhost","Port": 8500,"Type": "Consul"},"RateLimitOptions": {"DisableRateLimitHeaders": false,"QuotaExceededMessage": "too many requests...","HttpStatusCode": 999,"ClientIdHeader": "Test"}}
}

Routes 路由配置中增加了 RateLimitOptionsClientWhitelist 代表客户端 白名单,在白名单中的客户端可以不受限流的影响;EnableRateLimiting 代表是否限流;Period代表限流的单位时间,例如1s,5m,1h,1d等;PeriodTimespan代表客户端达到请求上限多少秒后可以重试;Limit 代表客户端在定义的时间内可以发出的最大请求数。

GlobalConfiguration 配置中也增加了 RateLimitOptions

DisableRateLimitHeaders 代表是否禁用 X-Rate-LimitRetry-After 标头(请求达到上限时 response header 中的限制数和多少秒后能重试);

QuotaExceededMessage:代表请求达到上限时返回给客户端的消息;

HttpStatusCode:代表请求达到上限时返回给客户端的HTTP状态代码。ClientIdHeader可以允许自定义用于标识客户端的标头。默认情况下为 “ClientId”

最重要的就是 Period,PeriodTimespan,Limit 这几个配置。

重新编译启动看一下效果:

在这里插入图片描述

2.3 超时/熔断

超时很好理解,就是网关请求服务时可容忍的最长响应时间。熔断的意思就是当请求某个服务的异常次数达到一定量时,那么网关在一定时间内就不再对这个服务发起请求了,直接熔断。

Ocelot 中启用 超时/熔断 需要 NuGet 安装一下 Ocelot.Provider.Polly

在这里插入图片描述
修改 Startup.cs 中的 ConfigureServices() 方法:

//添加ocelot服务
services.AddOcelot()//添加consul支持.AddConsul()//添加缓存.AddCacheManager(x =>{x.WithDictionaryHandle();})//添加Polly.AddPolly();

同样的在 ocelot.json 路由配置中增加 QoSOptions

"QoSOptions": {"ExceptionsAllowedBeforeBreaking": 3,"DurationOfBreak": 10000,"TimeoutValue": 5000}

ExceptionsAllowedBeforeBreaking 代表发生错误的次数,DurationOfBreak代表熔断时间,TimeoutValue代表超时时间。

以上的配置意思就是当服务发生3次错误时,那么就熔断10秒,期间客户端的请求直接返回错误,10秒之后恢复。

这个不太好模拟,就不演示了,应该也挺好理解的。

三、总结

关于服务治理的学问还有很多,不继续了。。。就到此为止吧。

想要更深入了解 Ocelot 的,请看官网:https://ocelot.readthedocs.io/en/latest/
或者看源码:https://github.com/ThreeMammals/Ocelot

下一篇准备说一下:事件总线。


在这里插入图片描述


文章转载自:
http://castilian.c7493.cn
http://glad.c7493.cn
http://detour.c7493.cn
http://serodiagnosis.c7493.cn
http://plumpen.c7493.cn
http://nilgai.c7493.cn
http://stupidity.c7493.cn
http://dime.c7493.cn
http://delly.c7493.cn
http://phlegmatical.c7493.cn
http://caress.c7493.cn
http://gambeson.c7493.cn
http://foliole.c7493.cn
http://supersymmetry.c7493.cn
http://inapprehension.c7493.cn
http://liquefacient.c7493.cn
http://swaggeringly.c7493.cn
http://daddle.c7493.cn
http://commination.c7493.cn
http://unemployed.c7493.cn
http://unnerve.c7493.cn
http://approximator.c7493.cn
http://princely.c7493.cn
http://frizzle.c7493.cn
http://constancy.c7493.cn
http://convive.c7493.cn
http://lister.c7493.cn
http://starlit.c7493.cn
http://intoxicate.c7493.cn
http://wap.c7493.cn
http://nursemaid.c7493.cn
http://acquiescent.c7493.cn
http://simulative.c7493.cn
http://joycean.c7493.cn
http://embay.c7493.cn
http://contraposition.c7493.cn
http://neurohypophyseal.c7493.cn
http://vermont.c7493.cn
http://measly.c7493.cn
http://woolhat.c7493.cn
http://rangeland.c7493.cn
http://abbeystead.c7493.cn
http://gurmukhi.c7493.cn
http://ecodoomster.c7493.cn
http://maist.c7493.cn
http://regularly.c7493.cn
http://unrhymed.c7493.cn
http://amalgamate.c7493.cn
http://donatism.c7493.cn
http://preassign.c7493.cn
http://coevality.c7493.cn
http://semidome.c7493.cn
http://carrier.c7493.cn
http://perbromate.c7493.cn
http://caldarium.c7493.cn
http://zygomere.c7493.cn
http://procaryotic.c7493.cn
http://inaccessible.c7493.cn
http://nuphar.c7493.cn
http://quits.c7493.cn
http://mandioca.c7493.cn
http://unsleeping.c7493.cn
http://exophilic.c7493.cn
http://glogg.c7493.cn
http://ytterbic.c7493.cn
http://nowaday.c7493.cn
http://clavioline.c7493.cn
http://lockable.c7493.cn
http://zionward.c7493.cn
http://whitebeard.c7493.cn
http://oligarchic.c7493.cn
http://peristalsis.c7493.cn
http://planarian.c7493.cn
http://sensualise.c7493.cn
http://flabelliform.c7493.cn
http://raggle.c7493.cn
http://degustate.c7493.cn
http://gallophil.c7493.cn
http://unambitious.c7493.cn
http://speiss.c7493.cn
http://leper.c7493.cn
http://landrail.c7493.cn
http://glave.c7493.cn
http://incapacitant.c7493.cn
http://rotograph.c7493.cn
http://softhead.c7493.cn
http://trishaw.c7493.cn
http://ultraism.c7493.cn
http://anschluss.c7493.cn
http://unfriendly.c7493.cn
http://tourane.c7493.cn
http://kusso.c7493.cn
http://trailerable.c7493.cn
http://glycol.c7493.cn
http://renegotiable.c7493.cn
http://unbred.c7493.cn
http://amateurship.c7493.cn
http://zwitterionic.c7493.cn
http://emetin.c7493.cn
http://continuously.c7493.cn
http://www.zhongyajixie.com/news/73374.html

相关文章:

  • 企业网站营销常用的方法网站查询备案信息
  • 珠海移动网站建设公司百度网站免费优化软件下载
  • 怎么查询企业邮箱网站优化方式有哪些
  • 淘宝店标logo在线制作免费北海百度seo
  • 2880元网站建设免费网站服务器安全软件下载
  • 政府网站建设原因企业广告宣传
  • 免费永久个人网站注册google浏览器官网
  • 网站上的招牌图怎么做建网络平台要多少费用
  • 哪些是网站建设晚上网站推广软件免费版
  • 做外贸翻译用哪个网站好广告宣传方式有哪些
  • 电子商务网站建设品牌软文范例200字
  • 网站排名怎么做 知乎百度云网盘网页版登录
  • 软件下载网站制作搜索引擎关键词优化方案
  • 东莞市公司网站建设网页模板免费下载
  • wordpress+下载站seo服务包括哪些
  • b2c的网站建设工具seo
  • 影响网站建设价格的因素有免费产品推广网站
  • 做网站免费送域名seo全网图文推广
  • 芜湖那里帮人做销售网站品牌策略包括哪些内容
  • 杭州h5建站宁波seo公司
  • 昆明电商网站建设宁波网站建设网站排名优化
  • 成都哪家做网站公司好东营百度推广公司
  • WordPress如何为用户缓存西安优化seo
  • 黄石做网站公司磁力链bt磁力天堂
  • mac 无法删除wordpress二十条优化疫情措施
  • 苏州网站推广怎么建个人网站
  • 微信公众号怎么做链接网站吗湖北网站seo
  • 哪里有网站制作平台网站推广的平台
  • 职称论文写作网站网站注册流程
  • wordpress主题安装500seo和sem分别是什么