15 changed files with 296 additions and 94 deletions
@ -1,57 +1,72 @@ |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Hosting; |
|||
using Serilog; |
|||
using System; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.MicroService.Internal.ApiGateway; |
|||
|
|||
namespace LINGYUN.MicroService.Internal.ApiGateway |
|||
{ |
|||
public class Program |
|||
{ |
|||
public static int Main(string[] args) |
|||
{ |
|||
try |
|||
{ |
|||
var hostBuilder = CreateHostBuilder(args).Build(); |
|||
Log.Information("Starting ApiGateway.Host."); |
|||
hostBuilder.Run(); |
|||
|
|||
return 0; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.Fatal(ex, "Host terminated unexpectedly!"); |
|||
return 1; |
|||
} |
|||
finally |
|||
{ |
|||
Log.CloseAndFlush(); |
|||
} |
|||
} |
|||
|
|||
internal static IHostBuilder CreateHostBuilder(string[] args) => |
|||
Host.CreateDefaultBuilder(args) |
|||
.ConfigureWebHostDefaults(webBuilder => |
|||
{ |
|||
webBuilder.UseStartup<Startup>(); |
|||
}) |
|||
.ConfigureAppConfiguration((context, config) => |
|||
{ |
|||
// 加入 ocelot配置文件
|
|||
config |
|||
.AddJsonFile($"ocelot.{context.HostingEnvironment.EnvironmentName ?? "Development"}.json", optional: true, reloadOnChange: true); |
|||
|
|||
var configuration = config.Build(); |
|||
if (configuration.GetSection("AgileConfig").Exists()) |
|||
{ |
|||
config.AddAgileConfig(new AgileConfig.Client.ConfigClient(configuration)); |
|||
} |
|||
}) |
|||
.UseSerilog((context, provider, config) => |
|||
{ |
|||
config.ReadFrom.Configuration(context.Configuration); |
|||
}) |
|||
.UseAutofac(); |
|||
} |
|||
public class Program |
|||
{ |
|||
public async static Task<int> Main(string[] args) |
|||
{ |
|||
try |
|||
{ |
|||
Log.Information("Starting Internal ApiGateway."); |
|||
|
|||
var builder = WebApplication.CreateBuilder(args); |
|||
builder.Host.AddAppSettingsSecretsJson() |
|||
.UseAutofac() |
|||
.ConfigureAppConfiguration((context, config) => |
|||
{ |
|||
// 加入 ocelot配置文件
|
|||
config.AddJsonFile( |
|||
$"ocelot.{context.HostingEnvironment.EnvironmentName ?? "Development"}.json", |
|||
optional: true, |
|||
reloadOnChange: true); |
|||
|
|||
var configuration = config.Build(); |
|||
if (configuration.GetSection("AgileConfig").Exists()) |
|||
{ |
|||
config.AddAgileConfig(new AgileConfig.Client.ConfigClient(configuration)); |
|||
} |
|||
}) |
|||
.UseSerilog((context, provider, config) => |
|||
{ |
|||
config.ReadFrom.Configuration(context.Configuration); |
|||
}); |
|||
await builder.AddApplicationAsync<InternalApiGatewayModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
var app = builder.Build(); |
|||
await app.InitializeApplicationAsync(); |
|||
await app.RunAsync(); |
|||
return 0; |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
Log.Fatal(ex, "Host terminated unexpectedly!"); |
|||
Console.WriteLine("Host terminated unexpectedly!"); |
|||
Console.WriteLine(ex.ToString()); |
|||
return 1; |
|||
} |
|||
finally |
|||
{ |
|||
Log.CloseAndFlush(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,31 +0,0 @@ |
|||
using Microsoft.AspNetCore.Builder; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using System.IO; |
|||
using Volo.Abp.IO; |
|||
using Volo.Abp.Modularity.PlugIns; |
|||
|
|||
namespace LINGYUN.MicroService.Internal.ApiGateway |
|||
{ |
|||
public class Startup |
|||
{ |
|||
public void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddApplication<InternalApiGatewayModule>(options => |
|||
{ |
|||
// 搜索 Modules 目录下所有文件作为插件
|
|||
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
|||
var pluginFolder = Path.Combine( |
|||
Directory.GetCurrentDirectory(), "Modules"); |
|||
DirectoryHelper.CreateIfNotExists(pluginFolder); |
|||
options.PlugInSources.AddFolder( |
|||
pluginFolder, |
|||
SearchOption.AllDirectories); |
|||
}); |
|||
} |
|||
|
|||
public void Configure(IApplicationBuilder app) |
|||
{ |
|||
app.InitializeApplication(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
{ |
|||
"Routes": [ |
|||
// 框架端点 |
|||
{ |
|||
"DownstreamPathTemplate": "/api/abp/application-configuration", |
|||
"DownstreamScheme": "http", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "127.0.0.1", |
|||
"Port": 30040 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/abp/task/application-configuration", |
|||
"UpstreamHttpMethod": [ "GET" ], |
|||
"LoadBalancerOptions": { |
|||
"Type": "RoundRobin" |
|||
}, |
|||
"RateLimitOptions": {}, |
|||
"QoSOptions": { |
|||
"ExceptionsAllowedBeforeBreaking": 10, |
|||
"DurationOfBreak": 1000, |
|||
"TimeoutValue": 10000 |
|||
}, |
|||
"HttpHandlerOptions": { |
|||
"UseTracing": true |
|||
}, |
|||
"Key": "task-configuration" |
|||
}, |
|||
// 框架动态API端点 |
|||
{ |
|||
"DownstreamPathTemplate": "/api/abp/api-definition", |
|||
"DownstreamScheme": "http", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "127.0.0.1", |
|||
"Port": 30040 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/abp/task/api-definition", |
|||
"UpstreamHttpMethod": [ "GET" ], |
|||
"LoadBalancerOptions": { |
|||
"Type": "RoundRobin" |
|||
}, |
|||
"RateLimitOptions": {}, |
|||
"QoSOptions": { |
|||
"ExceptionsAllowedBeforeBreaking": 10, |
|||
"DurationOfBreak": 1000, |
|||
"TimeoutValue": 10000 |
|||
}, |
|||
"HttpHandlerOptions": { |
|||
"UseTracing": true |
|||
}, |
|||
"Key": "task-api-definition" |
|||
}, |
|||
// 任务管理 |
|||
{ |
|||
"DownstreamPathTemplate": "/api/task-management/{everything}", |
|||
"DownstreamScheme": "http", |
|||
"DownstreamHostAndPorts": [ |
|||
{ |
|||
"Host": "127.0.0.1", |
|||
"Port": 30040 |
|||
} |
|||
], |
|||
"UpstreamPathTemplate": "/api/task-management/{everything}", |
|||
"UpstreamHttpMethod": [ "GET", "POST", "PUT", "DELETE" ], |
|||
"LoadBalancerOptions": { |
|||
"Type": "RoundRobin" |
|||
}, |
|||
"RateLimitOptions": { |
|||
"ClientWhitelist": [], |
|||
"EnableRateLimiting": true, |
|||
"Period": "1s", |
|||
"PeriodTimespan": 1, |
|||
"Limit": 5 |
|||
}, |
|||
"QoSOptions": { |
|||
"ExceptionsAllowedBeforeBreaking": 10, |
|||
"DurationOfBreak": 1000, |
|||
"TimeoutValue": 10000 |
|||
}, |
|||
"HttpHandlerOptions": { |
|||
"UseTracing": true |
|||
} |
|||
} |
|||
] |
|||
} |
|||
Loading…
Reference in new issue