//往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; } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline public void Configure(IApplicationBuilder app, IHostingEnvironment env, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) { //-------------------------------------------------------serilog 配置 AuthLogOptions authLogOptions = new AuthLogOptions() { LogPath = "D:\\LogFiles_TokenAuth",//Configuration[nameof(AuthLogOptions.LogPath)], PathFormat = "Auth_{Date}.log" }; var serilog = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.RollingFile(Path.Combine(authLogOptions.LogPath, authLogOptions.PathFormat), outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message}{NewLine}{Exception}"); AuthLogOptions.EnsurePreConditions(authLogOptions); 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(authLogOptions);//这个中间件用作记录请求中的过程日志 //---------------------------------------------------serilog 配置 //loggerFactory.AddConsole(Configuration.GetSection("Logging")); //loggerFactory.AddDebug(); app.UseMvc(); app.UseStaticFiles(); // Add JWT generation endpoint: var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey)); var options = new TokenProviderOptions { Audience = "JyAudience", Issuer = "JyIssuer", Expiration = new TimeSpan(0, 30, 0), SigningCredentials = new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256), }; app.UseMiddleware <TokenProviderMiddleware>(Options.Create(options)); app.UseMvc(); //往zookeeper注册服务 TokenAuthRegister.registerTokenAuthHostPort(Configuration.GetSection("UrlConfig").GetValue <string>("ZooKeeperList")); }
public override Task process(WatchedEvent @event) { var state = @event.getState(); if (Event.KeeperState.Disconnected == state) { TokenAuthRegister.registerTokenAuthHostPort(_zooKeeperURL); } var type = @event.get_Type(); if (type != Event.EventType.None) { //events.Add(@event); } return(default(Task)); }