Example #1
0
        public async Task Regist(IEnumerable <Assembly> assemblyList, ServiceAddress serverAddress)
        {
            using (var client = CreateClient())
            {
                foreach (var ass in assemblyList)
                {
                    var assName = ass.GetName();
                    var service = new AgentServiceRegistration
                    {
                        ID   = $"{ass.GetName().Name}_{serverAddress}".Md5(),
                        Name = assName.Name,
                        Tags = new[] { $"{Consts.Mode}" },
                        EnableTagOverride = true,
                        Address           = serverAddress.Address(),
                        Port = serverAddress.Port,
                        Meta = new Dictionary <string, string>
                        {
                            { "serverAddress", serverAddress.ToJson() }
                        }
                    };
                    _services.Add(service.ID);
                    var result = await client.Agent.ServiceRegister(service);

                    if (result.StatusCode != HttpStatusCode.OK)
                    {
                        _logger.Warn(
                            $"服务注册失败 [{assName.Name},{serverAddress}]:{result.StatusCode},{result.RequestTime}");
                    }
                    else
                    {
                        _logger.Info($"服务注册成功 [{assName.Name},{serverAddress}]");
                    }
                }
            }
        }