Пример #1
0
        public static DiscoverableEndpoint ConvertConsulTagsToDiscoveryEndpoint(this string[] tags)
        {
            var parsed = ConsulHelper.Parse(tags);

            if (parsed.ContainsKey(ConsulHelper.BoundedContext) == false)
            {
                return(null);
            }
            if (parsed.ContainsKey(ConsulHelper.UpdatedAt) == false)
            {
                return(null);
            }
            if (parsed.ContainsKey(ConsulHelper.IntroducedAtVersion) == false)
            {
                return(null);
            }
            if (parsed.ContainsKey(ConsulHelper.EndpointName) == false)
            {
                return(null);
            }
            if (parsed.ContainsKey(ConsulHelper.EndpointUrl) == false)
            {
                return(null);
            }

            string name                = parsed[ConsulHelper.EndpointName];
            string boundedContext      = parsed[ConsulHelper.BoundedContext];
            string endpointUrl         = parsed[ConsulHelper.EndpointUrl];
            string introducedAtVersion = parsed[ConsulHelper.IntroducedAtVersion];
            var    depricatedAtVersion = string.Empty;

            parsed.TryGetValue(ConsulHelper.DepricatedAtVersion, out depricatedAtVersion);

            return(new DiscoverableEndpoint(name, new Uri(endpointUrl), boundedContext, new DiscoveryVersion(introducedAtVersion, depricatedAtVersion)));
        }
Пример #2
0
        public void UnRegisterServices(string boundedContext)
        {
            var services = client.Agent.Services().Result;

            foreach (var service in services.Response)
            {
                if (service.Value != null && service.Value.Tags != null)
                {
                    var parsed = ConsulHelper.Parse(service.Value.Tags);
                    if (parsed.ContainsKey(ConsulHelper.BoundedContext) == true && parsed[ConsulHelper.BoundedContext] == boundedContext)
                    {
                        client.Agent.ServiceDeregister(service.Key);
                    }
                }
            }
        }
Пример #3
0
        public DiscoveryReaderResponseModel Get(string boundedContext)
        {
            long globalUpdatedAt = 0;
            var  foundEndpoints  = new HashSet <DiscoverableEndpoint>();

            var result = client.Catalog.Services().Result;

            if (ReferenceEquals(null, result) == true || result.StatusCode != System.Net.HttpStatusCode.OK)
            {
                return(new DiscoveryReaderResponseModel(globalUpdatedAt, foundEndpoints));
            }

            var publicServices = result.Response.Where(x => x.Value.Any(y => ConsulHelper.IsPublic(y) == true));

            foreach (var publicService in publicServices)
            {
                var parsedTags = ConsulHelper.Parse(publicService.Value);
                if (parsedTags.ContainsDiscoverableEndpointTags() == false)
                {
                    continue;
                }
                if (parsedTags.TagsArePartOfBoundedContext(boundedContext) == false)
                {
                    continue;
                }

                DiscoverableEndpoint consulEndpoint = publicService.Value.ConvertConsulTagsToDiscoveryEndpoint();
                foundEndpoints.Add(consulEndpoint);
                long serviceUpdatedAt = GetServiceUpdatedAt(publicService.Key);
                if (serviceUpdatedAt > globalUpdatedAt)
                {
                    globalUpdatedAt = serviceUpdatedAt;
                }
            }

            return(new DiscoveryReaderResponseModel(globalUpdatedAt, foundEndpoints));
        }
Пример #4
0
        public static long GetUpdatedAtTimestamp(this string[] tags)
        {
            var parsed = ConsulHelper.Parse(tags);

            return(GetUpdatedAtTimestamp(parsed));
        }