Exemplo n.º 1
0
        public override Collection <RegisterMeta> lookup(ServiceMeta serviceMeta)
        {
            string directory = $"/meou/provider/{serviceMeta.getGroup()}/{serviceMeta.getName()}/{serviceMeta.getVersion()}";
            List <RegisterMeta> registerMetaList = new List <RegisterMeta>();

            try
            {
                var children = configClient.GetChildrenAsync(directory).ConfigureAwait(false).GetAwaiter().GetResult();

                foreach (string p in children)
                {
                    registerMetaList.Add(parseRegisterMeta($"{directory}/{p}"));
                }
            }
            catch (Exception e)
            {
                if (logger.IsEnabled(LogLevel.Warning))
                {
                    logger.LogWarning($"Lookup service meta: {serviceMeta} path failed, {e}.");
                }
            }
            return(new Collection <RegisterMeta>(registerMetaList));
        }
Exemplo n.º 2
0
        protected override void doSubscribe(ServiceMeta serviceMeta)
        {
            string           directory     = $"/meou/provider/{serviceMeta.getGroup()}/{serviceMeta.getName()}/{serviceMeta.getVersion()}";
            IZKChildListener childListener = new ZKChildListener();

            childListener.ChildChangeHandler = (parentPath, currentChilds) =>
            {
                var          list = new List <RegisterMeta>(currentChilds.Count);
                RegisterMeta temp = null;
                foreach (var child in currentChilds)
                {
                    temp = parseRegisterMeta($"{parentPath}/{child}");
                    list.Add(temp);
                }

                notify(serviceMeta, list);

                return(Task.CompletedTask);
            };

            //childListener.ChildCountChangedHandler = async (parentPath, currentChilds) =>
            //{
            //    await notify(serviceMeta, NotifyEvent.CHILD_ADDED, 1L, new List<RegisterMeta>());
            //};
            configClient.SubscribeChildChanges(directory, childListener);
        }