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

在这里插入图片描述

在这里插入图片描述

网关 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}}
}

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

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

相关文章

数据结构与算法(test1)

一、树和二叉树 1. 看图&#xff0c;完成以下填空 (1).树的度为________。 (2).树中结点的最大层次&#xff0c;称为树的_____或树的______&#xff0c;值是______。 (3).结点A和B的度分别为________ 和 ________。 (4).结点A是结点B的________。 (5).结点B是结点A的________…

【GitLab CI/CD 实践】从 0 到 1 搭建高效自动化部署流程

网罗开发 &#xff08;小红书、快手、视频号同名&#xff09; 大家好&#xff0c;我是 展菲&#xff0c;目前在上市企业从事人工智能项目研发管理工作&#xff0c;平时热衷于分享各种编程领域的软硬技能知识以及前沿技术&#xff0c;包括iOS、前端、Harmony OS、Java、Python等…

Kubernetes是什么?为什么它是云原生的基石

从“手工时代”到“自动化工厂” 想象一下&#xff0c;你正在经营一家工厂。在传统模式下&#xff0c;每个工人&#xff08;服务器&#xff09;需要手动组装产品&#xff08;应用&#xff09;&#xff0c;效率低下且容易出错。而Kubernetes&#xff08;k8s&#xff09;就像一个…

算法与数据结构(删除有序数组的重复项)

思路 题目要求需要在原地删除重复的元素&#xff0c;这说明不能使用额外的空间。我们可以使用一个索引index来记录赋值的位置&#xff0c;以此来不断地删除重复的元素。 解题过程: 我们可以首先求得nums的长度len 若没有元素&#xff0c;直接返回0。 从第二个元素开始遍历…

[论文阅读] Knowledge Fusion of Large Language Models

Knowledge Fusion of Large Language Models (FuseLLM) Methodology 整体Pipeline如下图所示 不同的动物代表不同的LLM。左边第一&#xff0c;第二分别是Ensemble以及Weight Merging方法。最右侧为本文提出的FuseLLM。 Ensemble: 融合多个models的预测结果&#xff0c;比如…

2024~2025学年佛山市普通高中教学质量检测(一)【高三数学】

一、选择题 本题共8小题&#xff0c;每小题5分&#xff0c;共40分。在每小题给出的四个选项中。只有一项是符合题目要求的。 1、若 5 z 2 i 1 \frac{5}{z}2i1 z5​2i1&#xff0c;则 z z z A. 1-2i B. 12i C. 2-i D. 2i2、已知集合 A { x ∣ 1 < x < a } A\left\{…

探索从传统检索增强生成(RAG)到缓存增强生成(CAG)的转变

在人工智能快速发展的当下&#xff0c;大型语言模型&#xff08;LLMs&#xff09;已成为众多应用的核心技术。检索增强生成&#xff08;RAG&#xff09;&#xff08;RAG 系统从 POC 到生产应用&#xff1a;全面解析与实践指南&#xff09;和缓存增强生成&#xff08;CAG&#x…

anaconda中可以import cv2,但是notebook中cv2 module not found

一、问题 anaconda中成功import cv2 但是jupyter notebook中却无法导入cv2 二、排查 anaconda中使用python路径如下&#xff1a; jupyter notebook中使用python路径如下&#xff1a; 可以发现路径不一致。 三、解决 ①查看可用的kernel ②选中想要修改的kernel&#xff0c;打…

【数据结构】_栈的结构与实现

目录 1. 栈的相关概念与结构 2. 栈的实现 2.1 栈实现的底层结构选择 2.2 Stack.h 2.3 Stack.c 2.4 Test_Stack.c 1. 栈的相关概念与结构 1、栈&#xff1a;一种特殊的线性表&#xff0c;只允许在固定的一端插入和删除数据&#xff1b; 允许进行数据插入和删除操作的一端…

mysql的cpu使用率100%问题排查

背景 线上mysql服务器经常性出现cpu使用率100%的告警&#xff0c; 因此整理一下排查该问题的常规流程。 1. 确认CPU占用来源 检查系统进程 使用 top 或 htop 命令&#xff0c;确认是否是 mysqld 进程导致CPU满载&#xff1a;top -c -p $(pgrep mysqld)2. 实时分析MySQL活动 …

某团面试题①—kudu读写流程

kudu 读写流程 前言 为什么会有kudu&#xff1f;先贴一个经典的图。 kudu诞生之前大数据的主要2种方式存储 静态数据 以hdfs引擎作为存储引擎&#xff0c;适用于高吞吐量的离线大数据分析场景&#xff0c;缺点是实现随机读写性能差&#xff0c;更新数据难 动态数据 以Hbase…

Deepseek本地部署指南:在linux服务器部署,在mac远程web-ui访问

1. 在Linux服务器上部署DeepSeek模型 要在 Linux 上通过 Ollama 安装和使用模型&#xff0c;您可以按照以下步骤进行操作&#xff1a; 步骤 1&#xff1a;安装 Ollama 安装 Ollama&#xff1a; 使用以下命令安装 Ollama&#xff1a; curl -sSfL https://ollama.com/download.…

go并发和并行

进程和线程 进程&#xff08;Process&#xff09;就是程序在操作系统中的一次执行过程&#xff0c;是系统进行资源分配和调度的基本单位&#xff0c;进程是一个动态概念&#xff0c;是程序在执行过程中分配和管理资源的基本单位&#xff0c;每一个进程都有一个自己的地址空间。…

element-ui rate 组件源码分享

评分组件&#xff0c;从三个方面分享&#xff1a; 1、页面结构。 2、组件属性。 3、组件方法。 一、页面结构&#xff1a; 主要有图标的、图标(默认或自定义图标)文字的、图标分数的。 二、属性。 2.1 value 2.2 max 最大分数。 2.3 disabled 是否只读 2.4 allow-half 是…

python学opencv|读取图像(五十六)使用cv2.GaussianBlur()函数实现图像像素高斯滤波处理

【1】引言 前序学习了均值滤波和中值滤波&#xff0c;对图像的滤波处理有了基础认知&#xff0c;相关文章链接为&#xff1a; python学opencv|读取图像&#xff08;五十四&#xff09;使用cv2.blur()函数实现图像像素均值处理-CSDN博客 python学opencv|读取图像&#xff08;…

HIVE如何注册UDF函数

如果注册UDF函数的时候报了上面的错误&#xff0c;说明hdfs上传的路径不正确&#xff0c; 一定要用下面的命令 hadoop fs -put /tmp/hive/111.jar /user/hive/warehouse 一定要上传到上面路径&#xff0c;这样在创建函数时&#xff0c;引用下面的地址就可以创建成功

紧跟潮流,将 DeepSeek 集成到 VSCode

Visual Studio Code&#xff08;简称 VSCode&#xff09;是一款由微软开发的免费开源代码编辑器&#xff0c;自 2015 年发布以来&#xff0c;凭借其轻便、强大、且拥有丰富扩展生态的特点&#xff0c;迅速成为了全球开发者的首选工具。VSCode 支持多平台操作系统&#xff0c;包…

HAL库 Systick定时器 基于STM32F103EZT6 野火霸道,可做参考

目录 1.时钟选择(这里选择高速外部时钟) ​编辑 2.调试模式和时基源选择: 3.LED的GPIO配置 这里用板子的红灯PB5 4.工程配置 5.1ms的systick中断实现led闪烁 源码: 6.修改systick的中断频率 7.systick定时原理 SysTick 定时器的工作原理 中断触发机制 HAL_SYSTICK_Co…

DeepSeek与llama本地部署(含WebUI)

DeepSeek从2025年1月起开始火爆&#xff0c;成为全球最炙手可热的大模型&#xff0c;各大媒体争相报道。我们可以和文心一言一样去官网进行DeepSeek的使用&#xff0c;那如果有读者希望将大模型部署在本地应该怎么做呢&#xff1f;本篇文章将会教你如何在本地傻瓜式的部署我们的…

【重新认识C语言----文件管理篇】

目录 ​编辑 -----------------------------------------begin------------------------------------- 引言 1. 文件的基本概念 2. 文件指针 3. 文件的打开与关闭 3.1 打开文件 3.2 关闭文件 4. 文件的读写操作 4.1 读取文件 4.1.1 使用fgetc()读取文件 4.1.2 使用fg…