//往zookeeper注册服务 public static void InitRegisterAPIHostPort(string nodeName, IConfigurationRoot Configuration) { switch (nodeName) { case NodeName.AuthAdmin: AuthAPIRegister.registerAuthAPIHostPort(Configuration.GetSection("UrlConfig").GetValue <string>("ZooKeeperList")); break; case NodeName.TokenAuth: TokenAuthRegister.registerTokenAuthHostPort(Configuration.GetSection("UrlConfig").GetValue <string>("ZooKeeperList")); break; } }
public override Task process(WatchedEvent @event) { var state = @event.getState(); if (Event.KeeperState.Disconnected == state) { AuthAPIRegister.registerAuthAPIHostPort(_zooKeeperURL); } var type = @event.get_Type(); if (type != Event.EventType.None) { //events.Add(@event); } return(default(Task)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApiVersionDescriptionProvider provider) { app.UseHealthCheck("/HealthCheck", null, new TimeSpan(0, 0, 10)); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //-------------------------------------------------------serilog 配置 MVCLogOptions mvcLogOptions = new MVCLogOptions() { LogPath = "D:\\LogFiles_AuthAdmin_API",//Configuration[nameof(AuthLogOptions.LogPath)], PathFormat = "{Date}.log" }; var serilog = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.RollingFile(Path.Combine(mvcLogOptions.LogPath, mvcLogOptions.PathFormat), outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message}{NewLine}{Exception}"); MVCLogOptions.EnsurePreConditions(mvcLogOptions); loggerFactory.AddSerilog(serilog.CreateLogger()); // Ensure any buffered events are sent at shutdown 日志的生命周期 IApplicationLifetime appLifetime = (IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime)); if (appLifetime != null) { appLifetime.ApplicationStopped.Register(Serilog.Log.CloseAndFlush); } app.UseAuthLog(mvcLogOptions);//这个中间件用作记录请求中的过程日志 //---------------------------------------------------serilog 配置 //app.UsePetapoco();//use Petapocomiddleware app.UseDapper(); //----dapper if (env.IsDevelopment()) { //开发环境异常处理 app.UseDeveloperExceptionPage(); } else { //生产环境异常处理 app.UseExceptionHandler("/Shared/Error"); } //使用静态文件 app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory()) }); ////Session //app.UseSession(new SessionOptions() { IdleTimeout = TimeSpan.FromMinutes(30) }); SeedData.Initialize(app.ApplicationServices); //EF初始化数据 app.UseMvcWithDefaultRoute(); app.UseSwagger() .UseSwaggerUI(options => { // build a swagger endpoint for each discovered API version foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant()); } }); //往zookeeper注册服务 AuthAPIRegister.registerAuthAPIHostPort(Configuration.GetSection("UrlConfig").GetValue <string>("ZooKeeperList")); //注册到eureka,springcloud服务发现的注册 //app.UseDiscoveryClient(); }