1. 服務(wù)注冊
對 Consul 進(jìn)行服務(wù)注冊之前,需要先部署一個服務(wù)站點,我們可以使用 ASP.NET Core 創(chuàng)建 Web 應(yīng)用程序,并且部署到 Ubuntu 服務(wù)器上。
ASP.NET Core Hell World 應(yīng)用程序示例代碼,只需要三個文件,Startup.cs
代碼:
public class Startup{ // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // 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) { loggerFactory.AddConsole(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); }