我刚开始和领事一起工作。我的领事服务成功运行如下:
但是,在注册新服务之后,在尝试地址http://127.0.0.1:8600之后,新服务不会出现在领事服务中,或者是失败的。我该如何在领事中正确注册我的新服务?这是我的代码:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddSingleton<IDnsQuery>(new LookupClient(IPAddress.Parse("127.0.0.1"), 8600));
}
如果您需要我服务的其他部分提供更多代码,请与我们联系。
我还使用了http://cecilphillip.com/using-consul-for-service-discovery-with-asp-net-core/链接,这似乎是我想要的,但不幸的是它没有编译,因为它不包含ConsulConfig
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ConsulConfig>(Configuration.GetSection("consulConfig"));
services.AddSingleton<IConsulClient, ConsulClient>(p => new ConsulClient(consulConfig =>
{
var address = Configuration["consulConfig:address"];
consulConfig.Address = new Uri(address);
}));
services.AddMvc();
}