Exemplo n.º 1
0
        public void Configure(IApplicationBuilder app, ILogger <Startup> logger)
        {
            app.UseRouting();
            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
                endpoints.MapHealthChecks("/health");
            });

            var ip   = Configuration["ip"];
            var port = Convert.ToInt32(Configuration["port"]);

            try {
                var result = ConsulHelper.ServiceRegister(logger, ip, port).Result;
                if (result.StatusCode != HttpStatusCode.OK)
                {
                    logger.LogError("注册服务失败。Result:{@result}", result);
                }
                else
                {
                    logger.LogInformation("注册服务成功。Result:{@result}", result);
                }
            }
            catch (Exception ex) {
                logger.LogError(ex, "注册服务发生错误。");
            }
        }
Exemplo n.º 2
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints => {
                endpoints.MapControllers();
                endpoints.MapHealthChecks("/health");
            });

            var ret = ConsulHelper.ServiceRegister(Configuration).Result;

            Console.WriteLine(JsonConvert.SerializeObject(ret, Formatting.Indented));
        }