コード例 #1
0
        private async Task RegisterService()
        {
            var list = new List <AddressModel>();

            foreach (var m in ServiceHostManager.GetContractInfo())
            {
                var model = new AddressModel()
                {
                    Url              = m.url,
                    ServiceNodeName  = ServiceManageHelper.ParseServiceName(m.contract),
                    EndpointNodeName = ServiceManageHelper.EndpointNodeName(this._node_id),
                };
                list.Add(model);
            }

            foreach (var m in list)
            {
                var service_path = this._base_path + "/" + m.ServiceNodeName;
                await this.Client.EnsurePath(service_path);

                var path = service_path + "/" + m.EndpointNodeName;
                var data = this._serializer.Serialize(m);
                if (await this.Client.ExistAsync_(path))
                {
                    await this.Client.SetDataAsync_(path, data);
                }
                else
                {
                    //创建临时节点,服务端下线自动删除
                    await this.Client.CreateNode_(path, CreateMode.EPHEMERAL, data);
                }
            }
        }
コード例 #2
0
        private async Task RegisterService()
        {
            var _node_id = this.Client.getSessionId().ToString();

            var list = this._contracts.Invoke().Select(x => new AddressModel()
            {
                Url              = x.Url,
                ServiceNodeName  = ServiceManageHelper.ParseServiceName(x.Contract),
                EndpointNodeName = ServiceManageHelper.EndpointNodeName(_node_id),
            }).ToList();

            var now = DateTime.Now;

            foreach (var m in list)
            {
                m.UpdateTime = now;

                var service_path = this._base_path + "/" + m.ServiceNodeName;
                await this.Client.EnsurePath(service_path);

                var path = service_path + "/" + m.EndpointNodeName;
                var data = this._serializer.Serialize(m);
                if (await this.Client.ExistAsync_(path))
                {
                    await this.Client.SetDataAsync_(path, data);
                }
                else
                {
                    //创建临时节点,服务端下线自动删除
                    await this.Client.CreateNode_(path, CreateMode.EPHEMERAL, data);
                }
            }
        }
コード例 #3
0
ファイル: ServiceRegister.cs プロジェクト: SamBai2016/hiwjcn
        private async Task RegisterService()
        {
            var list = new List <AddressModel>();

            foreach (var a in this._ass)
            {
                var contractImpl = a.FindServiceContractsImpl();

                foreach (var t in contractImpl)
                {
                    var attr = t.GetCustomAttributes_ <ServiceContractImplAttribute>().First();
                    foreach (var contract in t.FindServiceContracts())
                    {
                        var model = new AddressModel()
                        {
                            Url              = this._base_url + attr.RelativePath,
                            ServiceNodeName  = ServiceManageHelper.ParseServiceName(contract),
                            EndpointNodeName = ServiceManageHelper.EndpointNodeName(this._node_id),
                        };
                        list.Add(model);
                    }
                }
            }

            foreach (var m in list)
            {
                var service_path = this._base_path + "/" + m.ServiceNodeName;
                await this.Client.EnsurePath(service_path);

                var path = service_path + "/" + m.EndpointNodeName;
                var data = this._serializer.Serialize(m);
                if (await this.Client.ExistAsync_(path))
                {
                    await this.Client.SetDataAsync_(path, data);
                }
                else
                {
                    //创建临时节点,服务端下线自动删除
                    await this.Client.CreateNode_(path, CreateMode.EPHEMERAL, data);
                }
            }
        }