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.Configuration; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.Extensions.Hosting; |
using Microsoft.Extensions.Hosting; |
||||
using Serilog; |
using Serilog; |
||||
using System; |
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 class Program |
public async static Task<int> Main(string[] args) |
||||
{ |
{ |
||||
public static int Main(string[] args) |
try |
||||
{ |
{ |
||||
try |
Log.Information("Starting Internal ApiGateway."); |
||||
{ |
|
||||
var hostBuilder = CreateHostBuilder(args).Build(); |
var builder = WebApplication.CreateBuilder(args); |
||||
Log.Information("Starting ApiGateway.Host."); |
builder.Host.AddAppSettingsSecretsJson() |
||||
hostBuilder.Run(); |
.UseAutofac() |
||||
|
.ConfigureAppConfiguration((context, config) => |
||||
return 0; |
{ |
||||
} |
// 加入 ocelot配置文件
|
||||
catch (Exception ex) |
config.AddJsonFile( |
||||
{ |
$"ocelot.{context.HostingEnvironment.EnvironmentName ?? "Development"}.json", |
||||
Log.Fatal(ex, "Host terminated unexpectedly!"); |
optional: true, |
||||
return 1; |
reloadOnChange: true); |
||||
} |
|
||||
finally |
var configuration = config.Build(); |
||||
{ |
if (configuration.GetSection("AgileConfig").Exists()) |
||||
Log.CloseAndFlush(); |
{ |
||||
} |
config.AddAgileConfig(new AgileConfig.Client.ConfigClient(configuration)); |
||||
} |
} |
||||
|
}) |
||||
internal static IHostBuilder CreateHostBuilder(string[] args) => |
.UseSerilog((context, provider, config) => |
||||
Host.CreateDefaultBuilder(args) |
{ |
||||
.ConfigureWebHostDefaults(webBuilder => |
config.ReadFrom.Configuration(context.Configuration); |
||||
{ |
}); |
||||
webBuilder.UseStartup<Startup>(); |
await builder.AddApplicationAsync<InternalApiGatewayModule>(options => |
||||
}) |
{ |
||||
.ConfigureAppConfiguration((context, config) => |
// 搜索 Modules 目录下所有文件作为插件
|
||||
{ |
// 取消显示引用所有其他项目的模块,改为通过插件的形式引用
|
||||
// 加入 ocelot配置文件
|
var pluginFolder = Path.Combine( |
||||
config |
Directory.GetCurrentDirectory(), "Modules"); |
||||
.AddJsonFile($"ocelot.{context.HostingEnvironment.EnvironmentName ?? "Development"}.json", optional: true, reloadOnChange: true); |
DirectoryHelper.CreateIfNotExists(pluginFolder); |
||||
|
options.PlugInSources.AddFolder( |
||||
var configuration = config.Build(); |
pluginFolder, |
||||
if (configuration.GetSection("AgileConfig").Exists()) |
SearchOption.AllDirectories); |
||||
{ |
}); |
||||
config.AddAgileConfig(new AgileConfig.Client.ConfigClient(configuration)); |
var app = builder.Build(); |
||||
} |
await app.InitializeApplicationAsync(); |
||||
}) |
await app.RunAsync(); |
||||
.UseSerilog((context, provider, config) => |
return 0; |
||||
{ |
} |
||||
config.ReadFrom.Configuration(context.Configuration); |
catch (Exception ex) |
||||
}) |
{ |
||||
.UseAutofac(); |
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