mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-04-04 16:16:35 +08:00
提交.Net6版本
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<log4net>
|
||||
<!-- 将日志以回滚文件的形式写到文件中 -->
|
||||
<!-- 按日期切分日志文件,并将日期作为日志文件的名字 -->
|
||||
<!--Error-->
|
||||
<appender name="ErrorLog" type="log4net.Appender.RollingFileAppender">
|
||||
<!--不加utf-8编码格式,中文字符将显示成乱码-->
|
||||
<param name="Encoding" value="utf-8" />
|
||||
<file value="log/"/>
|
||||
<appendToFile value="true" />
|
||||
<rollingStyle value="Date" />
|
||||
<!--日期的格式,每天换一个文件记录,如不设置则永远只记录一天的日志,需设置-->
|
||||
<datePattern value=""GlobalExceptionLogs_"yyyyMMdd".log"" />
|
||||
<!--日志文件名是否为静态-->
|
||||
<StaticLogFileName value="false"/>
|
||||
<!--多线程时采用最小锁定-->
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<!--布局(向用户显示最后经过格式化的输出信息)-->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date| %-5level %newline%message%newline--------------------------------%newline" />
|
||||
</layout>
|
||||
<filter type="log4net.Filter.LevelRangeFilter">
|
||||
<levelMin value="ERROR" />
|
||||
<levelMax value="FATAL" />
|
||||
</filter>
|
||||
</appender>
|
||||
<!--Error-->
|
||||
|
||||
|
||||
|
||||
<!--Info-->
|
||||
<appender name="InfoLog" type="log4net.Appender.RollingFileAppender">
|
||||
<!--不加utf-8编码格式,中文字符将显示成乱码-->
|
||||
<param name="Encoding" value="utf-8" />
|
||||
<!--定义文件存放位置-->
|
||||
<file value="log/"/>
|
||||
<appendToFile value="true" />
|
||||
<rollingStyle value="Date" />
|
||||
<!--日志文件名是否为静态-->
|
||||
<StaticLogFileName value="false"/>
|
||||
<!--日期的格式,每天换一个文件记录,如不设置则永远只记录一天的日志,需设置-->
|
||||
<datePattern value=""GlobalInfoLogs_"yyyyMMdd".log"" />
|
||||
<!--多线程时采用最小锁定-->
|
||||
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
|
||||
<!--布局(向用户显示最后经过格式化的输出信息)-->
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date| %-5level%c %newline%message%newline--------------------------------%newline" />
|
||||
</layout>
|
||||
<filter type="log4net.Filter.LevelRangeFilter">
|
||||
<levelMin value="DEBUG" />
|
||||
<levelMax value="WARN" />
|
||||
</filter>
|
||||
</appender>
|
||||
<!--Info-->
|
||||
|
||||
<root>
|
||||
<!-- 控制级别,由低到高:ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF -->
|
||||
<!-- 比如定义级别为INFO,则INFO级别向下的级别,比如DEBUG日志将不会被记录 -->
|
||||
<!-- 如果没有定义LEVEL的值,则缺省为DEBUG -->
|
||||
<level value="ALL" />
|
||||
<!-- 按日期切分日志文件,并将日期作为日志文件的名字 -->
|
||||
<appender-ref ref="ErrorLog" />
|
||||
<appender-ref ref="InfoLog" />
|
||||
</root>
|
||||
</log4net>
|
||||
@@ -1,42 +0,0 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((hostBuilderContext, configurationBuilder) =>
|
||||
{
|
||||
configurationBuilder.AddCommandLine(args);
|
||||
configurationBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
|
||||
configurationBuilder.AddJsonFile("configuration.json", optional: false, reloadOnChange: true);
|
||||
#region
|
||||
//ApolloÅäÖÃ
|
||||
#endregion
|
||||
//configurationBuilder.AddApolloService("Yi");
|
||||
})
|
||||
.ConfigureLogging(loggingBuilder =>
|
||||
{
|
||||
loggingBuilder.AddFilter("System", Microsoft.Extensions.Logging.LogLevel.Warning);
|
||||
loggingBuilder.AddFilter("Microsoft", Microsoft.Extensions.Logging.LogLevel.Warning);
|
||||
loggingBuilder.AddLog4Net();
|
||||
})
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>().UseUrls("http://*:7200");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:54400",
|
||||
"sslPort": 44373
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Yi.Framework.OcelotGateway": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": "true",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Provider.Consul;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Ocelot.Cache.CacheManager;
|
||||
using Yi.Framework.WebCore.MiddlewareExtend;
|
||||
using Ocelot.Provider.Polly;
|
||||
|
||||
namespace Yi.Framework.OcelotGateway
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
services.AddControllers();
|
||||
#region
|
||||
//跨域服务配置
|
||||
#endregion
|
||||
services.AddCorsService();
|
||||
|
||||
#region
|
||||
//网关服务配置
|
||||
#endregion
|
||||
services.AddOcelot().AddConsul().AddCacheManager(x =>{x.WithDictionaryHandle();}).AddPolly();
|
||||
|
||||
#region
|
||||
//Swagger服务配置
|
||||
#endregion
|
||||
services.AddSwaggerService<Program>("Yi.Framework.OcelotGateway");
|
||||
#region
|
||||
//Jwt鉴权配置
|
||||
#endregion
|
||||
services.AddJwtService();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
//if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
#region
|
||||
//Swagger服务注入
|
||||
#endregion
|
||||
app.UseSwaggerService(new SwaggerModel("api/api/swagger/v1/swagger.json","API服务"), new SwaggerModel("api/item/swagger/v1/swagger.json", "静态页服务"));
|
||||
}
|
||||
#region
|
||||
//网关服务注入
|
||||
#endregion
|
||||
app.UseOcelot();
|
||||
|
||||
#region
|
||||
//鉴权注入
|
||||
#endregion
|
||||
app.UseAuthentication();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DocumentationFile>D:\CC.Yi\CC.Yi\Yi.Framework\Yi.Framework.OcelotGateway\SwaggerDoc.xml</DocumentationFile>
|
||||
<NoWarn>1701;1702;CS1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Ocelot" Version="17.0.0" />
|
||||
<PackageReference Include="Ocelot.Cache.CacheManager" Version="17.0.0" />
|
||||
<PackageReference Include="Ocelot.Provider.Consul" Version="17.0.0" />
|
||||
<PackageReference Include="Ocelot.Provider.Polly" Version="17.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.WebCore\Yi.Framework.WebCore.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Apollo": {
|
||||
"AppId": "Yi.Framework.OcelotGateway",
|
||||
"Env": "DEV",
|
||||
"MetaServer": "http://192.168.2.168:8080",
|
||||
"ConfigServer": [ "http://192.168.2.168:8080" ]
|
||||
},
|
||||
"JWTTokenOptions": {
|
||||
"Audience": "http://localhost:7000",
|
||||
"Issuer": "http://localhost:7000",
|
||||
"SecurityKey": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDI2a2EJ7m872v0afyoSDJT2o1+SitIeJSWtLJU8/Wz2m7gStexajkeD+Lka6DSTy8gt9UwfgVQo6uKjVLG5Ex7PiGOODVqAEghBuS7JzIYU5RvI543nNDAPfnJsas96mSA7L/mD7RTE2drj6hf3oZjJpMPZUQI/B1Qjb5H3K3PNwIDAQAB"
|
||||
}
|
||||
}
|
||||
@@ -1,432 +0,0 @@
|
||||
////*****************************单地址多实例负载均衡+Consul********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "UpstreamPathTemplate": "/T/{url}", //网关地址--url变量
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "UseServiceDiscovery": true,
|
||||
// "ServiceName": "ZhaoxiService", //consul服务名称
|
||||
// "LoadBalancerOptions": {
|
||||
// "Type": "RoundRobin" //轮询 LeastConnection-最少连接数的服务器 NoLoadBalance不负载均衡
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// "GlobalConfiguration": {
|
||||
// "BaseUrl": "http://127.0.0.1:6299", //网关对外地址
|
||||
// "ServiceDiscoveryProvider": {
|
||||
// "Host": "47.95.2.2",
|
||||
// "Port": 8089,
|
||||
// "Type": "Consul" //由Consul提供服务发现, 每次请求去consul
|
||||
// } //Ocelot没有支持配置多个Consul
|
||||
|
||||
// //,"ServiceDiscoveryProvider": {
|
||||
// // "Host": "localhost",
|
||||
// // "Port": 8500,
|
||||
// // "Type": "PollConsul", //由Consul提供服务发现,
|
||||
// // "PollingInterval": 1000 //轮询consul,频率毫秒--down掉是不知道的
|
||||
// // //"Token": "footoken"//需要ACL的话
|
||||
// //}
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
//*****************************Ocelot+Consul********************************
|
||||
{
|
||||
"Routes": [
|
||||
{
|
||||
"UpstreamPathTemplate": "api/api/{url}", //上游请求地址--网关
|
||||
"UpstreamHttpMethod": [ "Get", "Post", "Put", "PATCH", "Delete", "Options" ],
|
||||
"UseServiceDiscovery": true,
|
||||
"ServiceName": "ApiMicroservice",
|
||||
"LoadBalancerOptions": {
|
||||
"Type": "RoundRobin" //轮询 LeastConnection-最少连接数的服务器 NoLoadBalance不负载均衡
|
||||
},
|
||||
"DownstreamPathTemplate": "api/api/{url}", //服务地址--url变量
|
||||
"DownstreamScheme": "https",
|
||||
"DownstreamHeaderTransform": {
|
||||
"Access-Control-Allow-Origin": "*", //不存在就添加
|
||||
"Access-Control-Allow-Methods": "*",
|
||||
"Access-Control-Allow-Headers": "*"
|
||||
}
|
||||
},
|
||||
{
|
||||
"UpstreamPathTemplate": "api/item/{url}", //上游请求地址--网关
|
||||
"UpstreamHttpMethod": [ "Get", "Post", "Put", "PATCH", "Delete", "Options" ],
|
||||
"UseServiceDiscovery": true,
|
||||
"ServiceName": "PageDetail",
|
||||
"LoadBalancerOptions": {
|
||||
"Type": "RoundRobin" //轮询 LeastConnection-最少连接数的服务器 NoLoadBalance不负载均衡
|
||||
},
|
||||
"DownstreamPathTemplate": "api/item/{url}", //服务地址--url变量
|
||||
"DownstreamScheme": "https",
|
||||
"DownstreamHeaderTransform": {
|
||||
"Access-Control-Allow-Origin": "*", //不存在就添加
|
||||
"Access-Control-Allow-Methods": "*",
|
||||
"Access-Control-Allow-Headers": "*"
|
||||
}
|
||||
}
|
||||
],
|
||||
"GlobalConfiguration": {
|
||||
"BaseUrl": "http://127.0.0.1:7200", //网关对外地址
|
||||
"ServiceDiscoveryProvider": {
|
||||
"Host": "192.168.2.128",
|
||||
"Port": 8500,
|
||||
"Type": "Consul" //由Consul提供服务发现, 每次请求去consul
|
||||
},
|
||||
"RateLimitOptions": {
|
||||
"QuotaExceededMessage": "你的请求过于频繁,请稍后再试!", // 当请求过载被截断时返回的消息
|
||||
"HttpStatusCode": 666 // 当请求过载被截断时返回的http status
|
||||
//"ClientIdHeader": "client_id" // 用来识别客户端的请求头,默认是 ClientId
|
||||
}
|
||||
|
||||
//,"ServiceDiscoveryProvider": {
|
||||
// "Host": "localhost",
|
||||
// "Port": 8500,
|
||||
// "Type": "PollConsul", //由Consul提供服务发现,
|
||||
// "PollingInterval": 1000 //轮询consul,频率毫秒--down掉是不知道的
|
||||
// //"Token": "footoken"//需要ACL的话
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
////*****************************单地址--无Consul********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "UpstreamPathTemplate": "/api/auth/{url}", //上游请求地址--网关
|
||||
// "UpstreamHttpMethod": [ "Get", "Post", "Put", "PATCH", "Delete", "Options" ],
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 7200 //网关api 端口
|
||||
// }
|
||||
// ],
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHeaderTransform": {
|
||||
// "Access-Control-Allow-Origin": "*", //不存在就添加
|
||||
// "Access-Control-Allow-Methods": "*",
|
||||
// "Access-Control-Allow-Headers": "*"
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
|
||||
////*****************************单地址全匹配********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5726 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/{url}", //网关地址--url变量 //冲突的还可以加权重Priority
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ]
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
|
||||
////*****************************多地址多实例********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5726 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/T5726/{url}", //网关地址--url变量
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ]
|
||||
// },
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5727 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/T5727/{url}", //网关地址--url变量
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ]
|
||||
// },
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5728 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/T5728/{url}", //网关地址--url变量
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ]
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
|
||||
//////MVC的路由规则是近水楼台先得月--
|
||||
////*****************************路由冲突+带权匹配********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5726 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/{url}", //网关地址--url变量 //冲突的还可以加权重Priority
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "Priority": 0 //默认是0 加个1
|
||||
// },
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/users/get?id={id}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5727 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/api/users/get/{id}", //网关地址--url变量 //冲突的还可以加权重Priority
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "Priority": 1 //默认是0 加个1
|
||||
// },
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/users/{url}?id={id}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5728 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/api/users/{url}/{id}", //网关地址--url变量 //冲突的还可以加权重Priority
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "Priority": 2 //默认是0 加个1
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
|
||||
////*****************************单地址多实例负载均衡********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "47.95.2.2",
|
||||
// "Port": 5726
|
||||
// }, //Ocelot负载均衡
|
||||
// {
|
||||
// "Host": "47.95.2.2",
|
||||
// "Port": 5727
|
||||
// },
|
||||
// {
|
||||
// "Host": "47.95.2.2",
|
||||
// "Port": 5728
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/T/{url}", //网关地址--url变量 //冲突的还可以加权重Priority
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "LoadBalancerOptions": {
|
||||
// "Type": "RoundRobin" //轮询 //"LeastConnection" //最少连接数的服务器 "NoLoadBalance" //不负载均衡 //"CookieStickySessions" //会话粘滞 //
|
||||
// }
|
||||
// //"LoadBalancerOptions": {
|
||||
// // "Type": "CookieStickySessions",
|
||||
// // "Key": "ASP.NET_SessionId",
|
||||
// // "Expiry": 1800000
|
||||
// //}
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
|
||||
////*****************************单地址多实例负载均衡+Consul********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "UpstreamPathTemplate": "/T/{url}", //网关地址--url变量
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "UseServiceDiscovery": true,
|
||||
// "ServiceName": "ZhaoxiService", //consul服务名称
|
||||
// "LoadBalancerOptions": {
|
||||
// "Type": "RoundRobin" //轮询 LeastConnection-最少连接数的服务器 NoLoadBalance不负载均衡
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// "GlobalConfiguration": {
|
||||
// "BaseUrl": "http://127.0.0.1:6299", //网关对外地址
|
||||
// "ServiceDiscoveryProvider": {
|
||||
// "Host": "47.95.2.2",
|
||||
// "Port": 8089,
|
||||
// "Type": "Consul" //由Consul提供服务发现, 每次请求去consul
|
||||
// } //Ocelot没有支持配置多个Consul
|
||||
|
||||
// //,"ServiceDiscoveryProvider": {
|
||||
// // "Host": "localhost",
|
||||
// // "Port": 8500,
|
||||
// // "Type": "PollConsul", //由Consul提供服务发现,
|
||||
// // "PollingInterval": 1000 //轮询consul,频率毫秒--down掉是不知道的
|
||||
// // //"Token": "footoken"//需要ACL的话
|
||||
// //}
|
||||
// }
|
||||
//}
|
||||
|
||||
////*****************************Consul+缓存Cache********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "UpstreamPathTemplate": "/T/{url}", //网关地址--url变量
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "UseServiceDiscovery": true,
|
||||
// "ServiceName": "ZhaoxiService", //consul服务名称
|
||||
// "LoadBalancerOptions": {
|
||||
// "Type": "RoundRobin" //轮询 LeastConnection-最少连接数的服务器 NoLoadBalance不负载均衡
|
||||
// },
|
||||
// "FileCacheOptions": {
|
||||
// "TtlSeconds": 15, //Second
|
||||
// "Region": "UserCache" //可以调用Api缓存清理
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// "GlobalConfiguration": {
|
||||
// "BaseUrl": "http://127.0.0.1:6299", //网关对外地址
|
||||
// "ServiceDiscoveryProvider": {
|
||||
// "Host": "47.95.2.2",
|
||||
// "Port": 8089,
|
||||
// "Type": "Consul" //由Consul提供服务发现, 每次请求去consul
|
||||
// }
|
||||
// //"ServiceDiscoveryProvider": {
|
||||
// // "Host": "localhost",
|
||||
// // "Port": 8500,
|
||||
// // "Type": "PollConsul", //由Consul提供服务发现,
|
||||
// // "PollingInterval": 1000 //轮询consul,频率毫秒--down掉是不知道的
|
||||
// // //"Token": "footoken"//需要ACL的话
|
||||
// //}
|
||||
// }
|
||||
//}
|
||||
|
||||
////*****************************超时+限流+熔断+降级+Consul+Polly********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/{url}", //服务地址--url变量
|
||||
// "DownstreamScheme": "http",
|
||||
// "UpstreamPathTemplate": "/T/{url}", //网关地址--url变量
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "UseServiceDiscovery": true,
|
||||
// "ServiceName": "ZhaoxiService", //consul服务名称
|
||||
// "LoadBalancerOptions": {
|
||||
// "Type": "RoundRobin" //轮询 LeastConnection-最少连接数的服务器 NoLoadBalance不负载均衡
|
||||
// },
|
||||
// "RateLimitOptions": {
|
||||
// "ClientWhitelist": [ "eleven", "seven" ], //白名单 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 如果下游请求的处理时间超过多少则自如将请求设置为超时 默认90秒
|
||||
// }
|
||||
// //"FileCacheOptions": {
|
||||
// // "TtlSeconds": 15,
|
||||
// // "Region": "UserCache" //可以调用Api清理
|
||||
// //}
|
||||
// }
|
||||
// ],
|
||||
// "GlobalConfiguration": {
|
||||
// "BaseUrl": "http://127.0.0.1:6299", //网关对外地址
|
||||
// "ServiceDiscoveryProvider": {
|
||||
// "Host": "47.95.2.2",
|
||||
// "Port": 8089,
|
||||
// "Type": "Consul" //由Consul提供服务发现
|
||||
// },
|
||||
// "RateLimitOptions": {
|
||||
// "QuotaExceededMessage": "Too many requests, maybe later? 11", // 当请求过载被截断时返回的消息
|
||||
// "HttpStatusCode": 666, // 当请求过载被截断时返回的http status
|
||||
// //"ClientIdHeader": "client_id" // 用来识别客户端的请求头,默认是 ClientId
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
////*****************************请求聚合Aggregator********************************
|
||||
//{
|
||||
// "Routes": [
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/users/all",
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5726 //服务端口
|
||||
// } //可以多个,自行负载均衡
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/T5726/users/all",
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "key": "T5726"
|
||||
// },
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/users/all",
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5727 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/T5727/users/all",
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "key": "T5727"
|
||||
// },
|
||||
// {
|
||||
// "DownstreamPathTemplate": "/api/users/all",
|
||||
// "DownstreamScheme": "http",
|
||||
// "DownstreamHostAndPorts": [
|
||||
// {
|
||||
// "Host": "localhost",
|
||||
// "Port": 5728 //服务端口
|
||||
// }
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/T5728/users/all",
|
||||
// "UpstreamHttpMethod": [ "Get", "Post" ],
|
||||
// "key": "T5728"
|
||||
// }
|
||||
// ],
|
||||
// "Aggregates": [
|
||||
// {
|
||||
// "RouteKeys": [
|
||||
// "T5726",
|
||||
// "T5727",
|
||||
// "T5728"
|
||||
// ],
|
||||
// "UpstreamPathTemplate": "/UserAggregator", //如果某个404 是不影响返回,当成null
|
||||
// "Aggregator": "CustomUserAggregator" //自定义聚合器
|
||||
// }
|
||||
// ]
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user