准备环境

 安装consul之后

1. 创建一个.net core webapi 举例为UsercenterService

2. nuget引用Consul组件  https://github.com/PlayFab/consuldotnet

3. 创建配置实体类 (后面涉及功能介绍时候再解释属性含义)

 1     public class AppSettings
 2     {
 3         /// <summary>
 4         /// 数据库连接字符串
 5         /// </summary>
 6         public string DbConnection { get; set; }
 7 
 8         /// <summary>
 9         /// 服务注册参数
10         /// </summary>
11         public ServiceRegisterOptions ServiceRegisterOptions { get; set; }
12     }
13 
14     public class ServiceRegisterOptions
15     {
16         /// <summary>
17         /// 是否启用
18         /// </summary>
19         public bool IsActive { get; set; }
20         /// <summary>
21         /// 服务名称
22         /// </summary>
23         public string ServiceName { get; set; }
24         /// <summary>
25         /// 服务IP或者域名
26         /// </summary>
27         public string ServiceHost { get; set; }
28         /// <summary>
29         /// 服务端口号
30         /// </summary>
31         public int ServicePort { get; set; }
32         /// <summary>
33         /// consul注册地址
34         /// </summary>
35         public string ConsulRegisterUrl { get; set; }
36         /// <summary>
37         /// 标签 例如laiwutest
38         /// </summary>
39         public string[] Tags { get; set; }
40     }
View Code

相关文章:

  • 2021-06-26
  • 2021-12-20
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-01-04
  • 2021-11-15
  • 2023-04-07
  • 2022-02-24
相关资源
相似解决方案