NetCore Consul动态伸缩+Ocelot 网关 缓存 自定义缓存 + 限流、熔断、超时 等服务治理 + ids4鉴权

在这里插入图片描述

在这里插入图片描述

网关 OcelotGeteway

在这里插入图片描述

网关 Ocelot配置文件

在这里插入图片描述

{//===========================单地址多实例==负载均衡==Consul=  实现动态伸缩============================"Routes": [{// 上游  》》 接受的请求//上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法"UpstreamHttpMethod": [ "Get", "Post" ],"UpstreamPathTemplate": "/P5001/{url}",           //下游》》对接受的请求 进行转发//下游路径模板"DownstreamPathTemplate": "/api/{url}","DownstreamScheme": "http",//支持Consul的服务发现 的配置 就是下面的  GlobalConfiguration配置"UseServiceDiscovery": true,//consul的服务名称 "ServiceName": "Zen",//能负载均衡,但是不能动态伸缩 consul"LoadBalancerOptions": {//RoundRobin>>轮询   LeastConnection  >>最少连接数的服务器  NoLoadBalance"Type": "RoundRobin"}}],"GlobalConfiguration": {//网关对外地址"BaseUrl": "Http://localhost:6299","ServiceDiscoveryProvider": {"Schema": "https","Host": "127.0.0.1","Port": 8500,"Type": "Consul" //由consul提供服务发现,每次请求去consul}     }   
}

网关以webapi 为例

在这里插入图片描述


using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Consul;namespace OcelotGateway
{public class Program{public static void Main(string[] args){var builder = WebApplication.CreateBuilder(args);// Add services to the container.//配置文件数据源builder.Configuration.AddJsonFile("Configuration.json", true,true);builder.Services.AddControllers();// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbucklebuilder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen();builder.Services.AddOcelot().AddConsul();var app = builder.Build();// Configure the HTTP request pipeline.if (app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}//接受请求,转发app.UseOcelot();            //app.UseHttpsRedirection();//app.UseAuthorization();//app.MapControllers();app.Run();}}
}

实际的提供服务的程序 以webapi为例

在这里插入图片描述

ConsulHelper

 public  static class ConsulHelper{/// <summary>/// Consul注册/// </summary>/// <param name="configuration"></param>public static void ConsulRegist(this IConfiguration configuration){//找ConsulConsulClient client = new ConsulClient(c => {c.Address = new Uri("http://localhost:8500");c.Datacenter = "dc1";});string ip = string.IsNullOrWhiteSpace(configuration["ip"]) ? "localhost" : configuration["ip"];int port = string.IsNullOrWhiteSpace(configuration["weight"]) ? 1 : int.Parse(configuration["port"]);int weight = string.IsNullOrWhiteSpace(configuration["weight"]) ? 1 : int.Parse(configuration["weight"]);client.Agent.ServiceRegister(new AgentServiceRegistration(){//唯一的 ID = "service" + Guid.NewGuid(),//分组Name = "Zen",Address = ip,Port = port,Tags = new string[] { weight.ToString() },//心跳Check = new AgentServiceCheck(){//间隔多久一次Interval = TimeSpan.FromSeconds(12),//控制器HTTP = $"http://{ip}:{port}/Api/Health/Index",//检测等等时间Timeout = TimeSpan.FromSeconds(5),//失败后多久移除DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(120)}});//命令行参数获取Console.WriteLine($"注册成功:{ip}{port}-weight:{weight}");}}

Program 中
在这里插入图片描述


using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using System.Net;
using System.Text;namespace WebAPI
{public class Program{public static void Main(string[] args){var builder = WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddControllers();// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbucklebuilder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen(options=>{options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme{Description = "请录入Token,格式:Bearer xxxx   Bearer 后面必须有个空格",Name = "Authorization",In = ParameterLocation.Header,Type = SecuritySchemeType.ApiKey,BearerFormat = "JWT",Scheme = "Bearer"});//添加安全要求options.AddSecurityRequirement(new OpenApiSecurityRequirement {{new OpenApiSecurityScheme{Reference =new OpenApiReference{Type = ReferenceType.SecurityScheme,Id ="Bearer"}},new string[]{ }}});});// 开启Bearer 认证builder.Services.AddAuthentication("Bearer") // 配置 JWT Bearer 选项.AddJwtBearer("Bearer", option =>{option.Authority = "https://localhost:2025";option.TokenValidationParameters = new TokenValidationParameters{// 验证发行者//ValidateIssuer = true,// 验证受众ValidateAudience = false,// 验证令牌有效期//ValidateLifetime = true,// 验证签名密钥//ValidateIssuerSigningKey = true,// 发行者//ValidIssuer = builder.Configuration["TokenParameter:Issuer"],// 受众// ValidAudience = builder.Configuration["JokenParameter:Audience"],// 签名密钥//IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["TokenParameter:Secret"])),//AudienceValidator = (m, n, z) =>//{//    //自定义验证逻辑//    return true;//}};});builder.Services.AddAuthorization(options =>{options.AddPolicy(name: "ApiScope", configurePolicy: policy =>{//需要认证的用户policy.RequireAuthenticatedUser();policy.RequireClaim("scope", "sample_api");});});var app = builder.Build();// Configure the HTTP request pipeline.if (app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}app.MapWhen(context => context.Request.Path.Equals("/api/Health/Index"),applicationBuilder => applicationBuilder.Run(async context =>{Console.WriteLine($"This is Health Check");context.Response.StatusCode = (int)HttpStatusCode.OK;await context.Response.WriteAsync("OK");}));app.UseAuthentication();app.UseAuthorization();app.MapControllers();//程序启动时执行   ------  且只执行一次app.Configuration.ConsulRegist();app.Run();}}
}

1、启动Consul

consul agent -dev

参考资料
2、启动webapi实际的服务

dotnet run --urls=“http://:2501" --port=2501 --ip=“localhost” --weight=2
dotnet run --urls="http://
:2502” --port=2502 --ip=“localhost” --weight=2
dotnet run --urls=“http://*:2503” --port=2503 --ip=“localhost” --weight=2
3、启动网关 Ocelot
dotnet run --urls=“http://localhost:6299”

源码

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

网关Ocelot + Cache 缓存

在这里插入图片描述
在这里插入图片描述
》》Ocelot program


using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Consul;
using Ocelot.Cache.CacheManager;
namespace OcelotGateway
{public class Program{public static void Main(string[] args){var builder = WebApplication.CreateBuilder(args);// Add services to the container.//配置文件数据源builder.Configuration.AddJsonFile("Configuration.json", true,true);builder.Services.AddControllers();// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbucklebuilder.Services.AddEndpointsApiExplorer();builder.Services.AddSwaggerGen();builder.Services.AddOcelot().AddConsul().AddCacheManager(x => {x.WithDictionaryHandle();//字典缓存});var app = builder.Build();// Configure the HTTP request pipeline.if (app.Environment.IsDevelopment()){app.UseSwagger();app.UseSwaggerUI();}//接受请求,转发app.UseOcelot();            //app.UseHttpsRedirection();//app.UseAuthorization();//app.MapControllers();app.Run();}}
}

》》》Ocelot 的配置文件
//缓存针对具体那个路由的

{"Routes": [{"UpstreamPathTemplate": "/T/{url}", //上游 网关地址   "UpstreamHttpMethod": [], // 空代表任意方式   【“Get” ,"Post"】"DownstreamPathTemplate": "/api/{url}", //服务地址>>真实的提供服务的"DownstreamSchema": "Http","UseServiceDiscovery": true, //开启服务发现 "ServiceName": "Zen", //Consul 服务名称"LoadBalancerOptions": {"Type": "RoundRobin" //轮询      LeastConnection  》最少连接数的服务器   NoLoadBalance  不负载},//鉴权//"AuthenticationOptins": {//    "AuthenticationProviderKey": "UserGatewayKey",//    "AllowedScope": []//},"FileCacheOptions": {"TtlSeconds": 15, //Ttl   Time To live"Region": "UserCache" //可以调用Api缓存清理}}], "GlobalConfiguration": {//网关对外地址"BaseUrl": "Http://localhost:6299","ServiceDiscoveryProvider": {"Schema": "https","Host": "127.0.0.1","Port": 8500,"Type": "Consul" //由consul提供服务发现,每次请求去consul}//"ServiceDiscoveryProvider": {//    "Host": "localhost",//    "Port": 8500,//    "Type": "PollConsul", //由consul提供服务发现//    "PollingInterval": 1000 //轮询consul  频率毫秒--down掉是不知道的//    //“Token":"footoken"/ /需要ACL的话//}}
}

自定义缓存

在这里插入图片描述
》》》

using Consul;
using Ocelot.Cache;namespace OcelotGateway.OcelotExtend
{/// <summary>/// 自定义的缓存扩展/// </summary>public class CustomCacheExtend : IOcelotCache<CachedResponse>{private readonly ILogger<CustomCacheExtend> logger;public CustomCacheExtend(ILogger<CustomCacheExtend> logger){this.logger = logger;}/// <summary>/// 存放缓存数据的字典,当然可以缓存在Redis 、Mongodb/// 可以提取出去 /// </summary>private class CacheDataModel{public required CachedResponse CachedResponse { get; set; }public DateTime Timeout { get; set; }public string Region { get; set; }}private static Dictionary<string,CacheDataModel> CustomCacheExtendDictionay=new Dictionary<string,CacheDataModel>();/// <summary>/// 没做过期处理,所以需要/// </summary>/// <param name="key"></param>/// <param name="value"></param>/// <param name="ttl"></param>/// <param name="region"></param>public void Add(string key, CachedResponse value, TimeSpan ttl, string region){this.logger.LogWarning($" This is {nameof(CustomCacheExtend)}.{nameof(Add)}");//CustomCacheExtendDictionay.Add(key, new CacheDataModel()//{//    CachedResponse = value,//    Region = region,//    Timeout = DateTime.Now.Add(ttl)//});CustomCacheExtendDictionay[key] = new CacheDataModel(){CachedResponse = value,Region = region,Timeout = DateTime.Now.Add(ttl)};//throw new NotImplementedException();}public void AddAndDelete(string key, CachedResponse value, TimeSpan ttl, string region){throw new NotImplementedException();}public void ClearRegion(string region){this.logger.LogWarning($"This is {nameof(CustomCacheExtend)}.{nameof(ClearRegion)}");var keyList=CustomCacheExtendDictionay.Where(kv=>kv.Value.Region.Equals(region)).Select(kv=>kv.Key);foreach (var key in keyList){CustomCacheExtendDictionay.Remove(key);}//throw new NotImplementedException();}public CachedResponse Get(string key, string region){this.logger.LogWarning($"This is {nameof(CustomCacheExtend)}.{nameof(Get)}");if (CustomCacheExtendDictionay.ContainsKey(key)&& CustomCacheExtendDictionay[key] != null&& CustomCacheExtendDictionay[key].Timeout > DateTime.Now&& CustomCacheExtendDictionay[key].Region.Equals(region)){return CustomCacheExtendDictionay[key].CachedResponse;}elsereturn null;//throw new NotImplementedException();}public bool TryGetValue(string key, string region, out CachedResponse value){throw new NotImplementedException();}}
}

在这里插入图片描述

网关 Ocelot 服务治理》》 限流

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

{"Routes": [{"DownstreamPathTemplate": "/api/{url}", //服务地址 --url 变量"DownstreamSchema": "http","UpstreamPathTemplate": "/T/{url}", //网关地址   --url变量"UpstreamHttpMethod": [ "Get", "Post" ],"UseServiceDiscovery": true,"ServiceName": "zen", //Consul 服务名称"LoadBalancerOptions": {"Type": "RoundRobin" //轮询},"RateLimitOptions": {"ClientWhitelist": [ "xx", "yy" ], //白名单 ClientId 区分大小写"EnableRateLimiting": true,//过期时间"Period": "5m", //1s   ,5m.1h,1d"PeriodTimespan": 30, //多少秒之后客户端可以重试"Limit": 5 //统计时间段内允许的最大请求数量},//"AuthenticationOptions": {//    "AuthenticationProviderKey": "UserGatewayKey",//    "AllowedScopes": []//},//"QoSOptions": {//    "ExceptionsAllowedBeforeBreaking": 3, //允许多少异常请求//    "DurationOfBreak": 10000, //熔断的时间   单位  ms//    "TimeoutValue": 2000 //单位ms   如果下游请求的处理时间超过多少则自如将请求设置为超时  默认90s//},//"FileCacheOptions": {//    "TtlSeconds": 15,//    "Region": "UserCache" //可以调用Api清理//}}],"GlobalConfiguration": {//网关对外地址"BaseUrl": "Http://localhost:6299","ServiceDiscoveryProvider": {"Schema": "https","Host": "127.0.0.1","Port": 8500,"Type": "Consul" //由consul提供服务发现,每次请求去consul},"RateLimitOptions": {"QuotaExceededMessage": "Too Many requests , maybe later ? ", //当请求过载被截断时返回的消息"HttpStatusCode": 666 ,//当请求过载被截断时返回的http status"ClientIdHeader": "Client_id"    //用来识别客户端的请求头    ,   默认是 ClientId}}
}

在这里插入图片描述
源码

Ocelot 配置文件

{===========================单地址======================================"Routes": [    {        // 上游  》》 接受的请求        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法        "UpstreamHttpMethod": [ "Get", "Post" ],        "UpstreamPathTemplate": "/T5726/{url}",        //下游》》对接受的请求 进行转发        //下游路径模板        "DownstreamPathTemplate": "/api/{url}",        "DownstreamScheme": "http",        "DownstreamHostAndPorts": [            {                "Host": "localhost",                "Port": 1005            }        ]    }]//===========================单地址====鉴权==================================//"Routes": [//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "UpstreamPathTemplate": "/xx/{url}",//        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/api/{url}",//        "DownstreamScheme": "http",//        "DownstreamHostAndPorts": [//            {//                "Host": "localhost",//                "Port": 1005//            }//        ],//        "AuthenticationOptins": {//            "AuthenticationProviderKey": "UserGatewayKey",//            "AllowedScopes": []//        }//    }//]//===========================单地址====全匹配=================================//"Routes": [//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        //冲突的还可以加权重 Priority//        "UpstreamPathTemplate": "/{url}",//        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/{url}",//        "DownstreamScheme": "http",//        "DownstreamHostAndPorts": [//            {//                "Host": "localhost",//                "Port": 1005//            }//        ]//    }//]========================多地址多实例===路由冲突+权重匹配======================================//"Routes": [//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "UpstreamPathTemplate": "/{url}",//        "Priority": 1, //默认是0 //        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/{url}",//        "DownstreamScheme": "http",//        "DownstreamHostAndPorts": [//            {//                "Host": "localhost",//                "Port": 1005//            }//        ]//    },//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "UpstreamPathTemplate": "/{url}",//        "Priority": 1, //默认是0 //        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/{url}",//        "DownstreamScheme": "http",//        "DownstreamHostAndPorts": [//            {//                "Host": "localhost",//                "Port": 1006//            }//        ]//    }//]===========================路由冲突+权重匹配======================================//"Routes": [//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "UpstreamPathTemplate": "/{url}",//        "Priority": 1, //默认是0 //        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/{url}",//        "DownstreamScheme": "http",//        "DownstreamHostAndPorts": [//            {//                "Host": "localhost",//                "Port": 1005//            }//        ]//    },//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "UpstreamPathTemplate": "/{url}",//        "Priority": 1, //默认是0 //        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/{url}",//        "DownstreamScheme": "http",//        "DownstreamHostAndPorts": [//            {//                "Host": "localhost",//                "Port": 1006//            }//        ]//    }//]//===========================单地址多实例==负载均衡===============================//"Routes": [//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "UpstreamPathTemplate": "/P5001/{url}",//        //能负载均衡,但是不能动态伸缩 consul//        "LoadBalancerOptions": {//            //RoundRobin>>轮询   LeastConnection  >>最少连接数的服务器  NoLoadBalance//            "Type": "RoundRobin"//        },//        //"LoadBalancerOptions": {//        //    //粘粘性//        //    "Type": "CookieStickySessions",//        //    "Key": "Asp.Net_SessionId",//        //    "Expiry": 180000//        //},//        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/api/{url}",//        "DownstreamScheme": "http",//        //无法动态伸缩   ==》consul  可以 //        "DownstreamHostAndPorts": [//            {//                "Host": "localhost",//                "Port": 1005//            },//            {//                "Host": "localhost",//                "Port": 1006//            },//            {//                "Host": "localhost",//                "Port": 1007//            }//        ]//    }       //]//===========================单地址多实例==负载均衡==Consul=  实现动态伸缩============================//"Routes": [//    {//        // 上游  》》 接受的请求//        //上游请求方法,可以设置特定的 HTTP 方法列表或设置空列表以允许其中任何方法//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "UpstreamPathTemplate": "/P5001/{url}",//        //"LoadBalancerOptions": {//        //    //粘粘性//        //    "Type": "CookieStickySessions",//        //    "Key": "Asp.Net_SessionId",//        //    "Expiry": 180000//        //},//        //下游》》对接受的请求 进行转发//        //下游路径模板//        "DownstreamPathTemplate": "/api/{url}",//        "DownstreamScheme": "http",//        //支持Consul的服务发现 的配置 就是下面的  GlobalConfiguration配置//        "UseServiceDiscovery": true,//        //consul的服务名称 //        "ServiceName": "Zen",//        //能负载均衡,但是不能动态伸缩 consul//        "LoadBalancerOptions": {//            //RoundRobin>>轮询   LeastConnection  >>最少连接数的服务器  NoLoadBalance//            "Type": "RoundRobin"//        }//    }//],//"GlobalConfiguration": {//    //网关对外地址//    "BaseUrl": "Http://localhost:6299",//    "ServiceDiscoveryProvider": {//        "Schema": "https",//        "Host": "127.0.0.1",//        "Port": 8500,//        "Type": "Consul" //由consul提供服务发现,每次请求去consul//    }//    //"ServiceDiscoveryProvider": {//    //    "Host": "localhost",//    //    "Port": 8500,//    //    "Type": "PollConsul", //由consul提供服务发现//    //    "PollingInterval": 1000 //轮询consul  频率毫秒--down掉是不知道的//    //    //“Token":"footoken"/ /需要ACL的话//    //}//}//********************************Consul   +   Cache  缓存 ***************************//"Routes": [//    {//        "UpstreamPathTemplate": "/T/{url}", //上游 网关地址   //        "UpstreamHttpMethod": [], // 空代表任意方式   【“Get” ,"Post"】//        "DownstreamPathTemplate": "/api/{url}", //服务地址>>真实的提供服务的//        "DownstreamSchema": "Http",//        "UseServiceDiscovery": true, //开启服务发现 //        "ServiceName": "Zen", //Consul 服务名称//        "LoadBalancerOptions": {//            "Type": "RoundRobin" //轮询      LeastConnection  》最少连接数的服务器   NoLoadBalance  不负载//        },//        //鉴权//        //"AuthenticationOptins": {//        //    "AuthenticationProviderKey": "UserGatewayKey",//        //    "AllowedScope": []//        //},//        "FileCacheOptions": {//            "TtlSeconds": 15, //Ttl   Time To live//            "Region": "UserCache" //可以调用Api缓存清理//        }//    }//], //"GlobalConfiguration": {//    //网关对外地址//    "BaseUrl": "Http://localhost:6299",//    "ServiceDiscoveryProvider": {//        "Schema": "https",//        "Host": "127.0.0.1",//        "Port": 8500,//        "Type": "Consul" //由consul提供服务发现,每次请求去consul//    }//    //"ServiceDiscoveryProvider": {//    //    "Host": "localhost",//    //    "Port": 8500,//    //    "Type": "PollConsul", //由consul提供服务发现//    //    "PollingInterval": 1000 //轮询consul  频率毫秒--down掉是不知道的//    //    //“Token":"footoken"/ /需要ACL的话//    //}//}//**************************单地址  +  Ids4****************************8//"Routes": [//    {//        "DownstreamPathTemplate": "/api/{url}", // 服务地址  --url变量//        "DownstreamSchema": "http",//        "DownstreamHostAndPorts": [//            {//                "Host": "127.0.0.1",//                "Port": 5726, //服务端口//            }//        ],//        "UpstreamPathTemplate": "/T/{url}", //官网 地址  --url变量//        "UpstreamHttpMethod": [ "Get", "Post" ],//        "AuthenticationOptions": {//            "AuthenticationProviderKey": "UserGatewayKey",//            "AllowedScopes": []//        }//    }//]//************************** 超时 限流 熔断 降级 Consul Polly ********************"Routes": [{"DownstreamPathTemplate": "/api/{url}", //服务地址 --url 变量"DownstreamSchema": "http","UpstreamPathTemplate": "/T/{url}", //网关地址   --url变量"UpstreamHttpMethod": [ "Get", "Post" ],"UseServiceDiscovery": true,"ServiceName": "zen", //Consul 服务名称"LoadBalancerOptions": {"Type": "RoundRobin" //轮询},"RateLimitOptions": {"ClientWhitelist": [ "xx", "yy" ], //白名单 ClientId 区分大小写"EnableRateLimiting": true,//过期时间"Period": "5m", //1s   ,5m.1h,1d"PeriodTimespan": 30, //多少秒之后客户端可以重试"Limit": 5 //统计时间段内允许的最大请求数量},//"AuthenticationOptions": {//    "AuthenticationProviderKey": "UserGatewayKey",//    "AllowedScopes": []//},//"QoSOptions": {//    "ExceptionsAllowedBeforeBreaking": 3, //允许多少异常请求//    "DurationOfBreak": 10000, //熔断的时间   单位  ms//    "TimeoutValue": 2000 //单位ms   如果下游请求的处理时间超过多少则自如将请求设置为超时  默认90s//},//"FileCacheOptions": {//    "TtlSeconds": 15,//    "Region": "UserCache" //可以调用Api清理//}}],"GlobalConfiguration": {//网关对外地址"BaseUrl": "Http://localhost:6299","ServiceDiscoveryProvider": {"Schema": "https","Host": "127.0.0.1","Port": 8500,"Type": "Consul" //由consul提供服务发现,每次请求去consul},"RateLimitOptions": {"QuotaExceededMessage": "Too Many requests , maybe later ? ", //当请求过载被截断时返回的消息"HttpStatusCode": 666 ,//当请求过载被截断时返回的http status"ClientIdHeader": "Client_id"    //用来识别客户端的请求头    ,   默认是 ClientId}}
}

Ocelot + ids4 鉴权

在这里插入图片描述

在这里插入图片描述
源码

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/14390.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

星网锐捷 DMB-BS LED屏信息发布系统taskexport接口处存在敏感信息泄露

星网锐捷 DMB-BS LED屏信息发布系统taskexport接口处存在敏感信息泄露 漏洞描述 福建星网锐捷通讯股份有限公司成立于2000年,公司秉承“融合创新科技,构建智慧未来"的经营理念,是国内领先的ICT基础设施及AI应用方案提供商。星网锐捷 DMB-BS LED屏信息发布系统taskexp…

国产高端双光子成像系统的自主突破

近年来&#xff0c;高端科研仪器的国产化受到越来越多的关注。在双光子成像系统这一关键领域&#xff0c;我们基于LabVIEW自主开发了一套完整的解决方案&#xff0c;不仅填补了国内空白&#xff0c;也在功能和性能上达到了国际领先水平。我们的目标是让国内科研机构和医疗行业拥…

Python多版本管理

关注后回复 python 获取相关资料 ubuntu18.04 # ubuntu18 默认版本 Python 2.7.17 apt install python python-dev python-pip# ubuntu18 默认版本 Python 3.6.9 apt install python3 python3-dev python3-pip# ubuntu18 使用 python3.8 apt install python3.8 python3.8-dev#…

详细教程 | 如何使用DolphinScheduler调度Flink实时任务

Apache DolphinScheduler 非常适用于实时数据处理场景&#xff0c;尤其是与 Apache Flink 的集成。DolphinScheduler 提供了丰富的功能&#xff0c;包括任务依赖管理、动态调度、实时监控和日志管理&#xff0c;能够有效简化 Flink 实时任务的管理和部署。通过 DolphinSchedule…

windows安装WSL完整指南

本文首先介绍WSL&#xff0c;然后一步一步安装WSL及Ubuntu系统&#xff0c;最后讲解如何在两个系统之间访问和共享文件信息。通过学习该完整指南&#xff0c;能帮助你快速安装WSL&#xff0c;解决安装和使用过程中的常见问题。 理解WSL&#xff08;Windows Subsystem for Linux…

kafka专栏解读

kafka专栏文章的编写将根据kafka架构进行编写&#xff0c;即先编辑kafka生产者相关的内容&#xff0c;再编写kafka服务端的内容&#xff08;这部分是核心&#xff0c;内容较多&#xff0c;包含kafka分区管理、日志存储、延时操作、控制器、可靠性等&#xff09;&#xff0c;最后…

【东莞常平】戴尔R710服务器不开机维修分享

1&#xff1a;2025-02-06一位老客户的朋友刚开工公司ERP服务器一台戴尔老服务器故障无法开机&#xff0c;于是经老客户介绍找到我们。 2&#xff1a;服务器型号是DELL PowerEdge R710 这个服务器至少也有15年以上的使用年限了。 3&#xff1a;客户反馈的故障问题为&#xff1a;…

win10 llamafactory模型微调相关① || Ollama运行微调模型

目录 微调相关 1.微调结果评估 2.模型下载到本地 导出转换&#xff0c;Ollama运行 1.模型转换&#xff08;非常好的教程&#xff01;&#xff09; 2.Ollama 加载GGUF模型文件 微调相关 1.微调结果评估 【06】LLaMA-Factory微调大模型——微调模型评估_llamafactory评估-C…

DeepSeek图解10页PDF

以前一直在关注国内外的一些AI工具&#xff0c;包括文本型、图像类的一些AI实践&#xff0c;最近DeepSeek突然爆火&#xff0c;从互联网收集一些资料与大家一起分享学习。 本章节分享的文件为网上流传的DeepSeek图解10页PDF&#xff0c;免费附件链接给出。 1 本地 1 本地部…

自动驾驶---聊聊传统规控和端到端

1 背景 在自动驾驶领域中&#xff0c;端到端模型的兴起确实对传统的规划控制方法&#xff08;笔者并不同意网上以Rule-Base称呼传统规控&#xff0c;传统的规控其实也使用了很多优化算法和博弈算法&#xff09;产生了挑战&#xff0c;但这就意味着传统规控方法就完全没有应用了…

【如何掌握CSP-J 信奥赛中的深搜算法】

CSP-J 信奥赛中的深搜&#xff08;深度优先搜索&#xff09;算法是一个重要知识点&#xff0c;以下是一些学习深搜算法的建议&#xff1a; 理解基础概念 定义与原理&#xff1a;深度优先搜索是一种用于遍历或搜索图、树等数据结构的算法。它从起始节点开始&#xff0c;沿着一条…

使用redis实现 令牌桶算法 漏桶算法

流量控制算法&#xff0c;用于限制请求的速率。 可以应对缓存雪崩 令牌桶算法 核心思想是&#xff1a; 有一个固定容量的桶&#xff0c;里面存放着令牌&#xff08;token&#xff09;。每过一定时间&#xff08;如 1 秒&#xff09;&#xff0c;桶中会自动增加一定数量的令牌…

LIMO:少即是多的推理

25年2月来自上海交大、SII 和 GAIR 的论文“LIMO: Less is More for Reasoning”。 一个挑战是在大语言模型&#xff08;LLM&#xff09;中的复杂推理。虽然传统观点认为复杂的推理任务需要大量的训练数据&#xff08;通常超过 100,000 个示例&#xff09;&#xff0c;但本文展…

C++,设计模式,【单例模式】

文章目录 一、模式定义与核心价值二、模式结构解析三、关键实现技术演进1. 基础版(非线程安全)2. 线程安全版(双重检查锁)3. 现代C++实现(C++11起)四、实战案例:全局日志管理器五、模式优缺点深度分析✅ 核心优势⚠️ 潜在缺陷六、典型应用场景七、高级实现技巧1. 模板化…

Mysql基于binlog主从同步配置

主配置&#xff1a; 修改配置文件&#xff1a;/etc/my.cnf 添加server-id1 重启MySQL服务&#xff1a;systemctl restart mysqld 创建用户并授权&#xff1a; mysql> create user rep192.168.79.% identified with mysql_native_password by 123456; Query OK, 0 rows aff…

postman使用简介

在使用非关系数据库&#xff0c;与远端数据库交互时&#xff0c;需要在本地测试程序逻辑。借助postman查询数据。 1、开启本地数据库 绑定资源中&#xff0c;有如下应用程序&#xff0c;双击后可开启数据库服务 2、使用postman 下载后可以打开界面&#xff0c;可以填入远端数…

什么是三层交换技术?与二层有什么区别?

什么是三层交换技术&#xff1f;让你的网络飞起来&#xff01; 一. 什么是三层交换技术&#xff1f;二. 工作原理三. 优点四. 应用场景五. 总结 前言 点个免费的赞和关注&#xff0c;有错误的地方请指出&#xff0c;看个人主页有惊喜。 作者&#xff1a;神的孩子都在歌唱 大家好…

amis组件crud使用踩坑

crud注意 过滤条件参数同步地址栏 默认 CRUD 会将过滤条件参数同步至浏览器地址栏中&#xff0c;比如搜索条件、当前页数&#xff0c;这也做的目的是刷新页面的时候还能进入之前的分页。 但也会导致地址栏中的参数数据合并到顶层的数据链中&#xff0c;例如&#xff1a;自动…

Baklib重塑内容中台智能推荐系统提高服务质量的策略和实操

内容概要 随着信息技术的飞速发展&#xff0c;企业在内容管理和用户体验方面面临越来越多的挑战。在这个大背景下&#xff0c;内容中台的智能化推荐系统应运而生&#xff0c;Baklib作为一个突出的工具&#xff0c;为企业提供了解决方案。Baklib 是什么类型的工具&#xff0c;它…

浅谈 HashMap 的扩容过程和 put 过程

这是在基于 JDK 1.8 之后的源码进行的浅谈 简介&#xff1a; 在 JDK 8 中&#xff0c;HashMap 由 “数组 链表 红黑树” 组成。链表过长会影响查询性能&#xff0c;而红黑树搜索的时间复杂度是 O(logn)&#xff0c;而链表则是O(n)&#xff0c;JDK 8 对数据结构进行了进一步的…