Ejemplo n.º 1
0
        public async Task <EventsPublishedByService> GetPublishedEventTypes(Uri serviceAdress)
        {
            var client = await _factory.GetClient(serviceAdress);

            try
            {
                var response = await client.GetAsync("Dicovery/PublishedEvents");

                _logger.LogTrace($"Response for Servicediscovery was {response.StatusCode}");
                if (!response.IsSuccessStatusCode)
                {
                    return(EventsPublishedByService.NotReachable(new ServiceEndPoint(serviceAdress)));
                }
                var content = await response.Content.ReadAsStringAsync();

                var events = JsonConvert.DeserializeObject <PublishedEventsByServiceDto>(content);

                return(EventsPublishedByService.Reachable(
                           new ServiceEndPoint(serviceAdress, events.ServiceName),
                           events.PublishedEvents));
            }
            catch (HttpRequestException)
            {
                return(EventsPublishedByService.NotReachable(new ServiceEndPoint(serviceAdress)));
            }
            catch (IOException)
            {
                return(EventsPublishedByService.NotReachable(new ServiceEndPoint(serviceAdress)));
            }
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <SubscribedDomainEventWrapper> > GetEventsAsync(long lastVersion = 0)
        {
            var client = await _clientFactory.GetClient <T>();

            try
            {
                if (client.BaseAddress != null)
                {
                    var response = await client.GetAsync($"?lastVersion={lastVersion}");

                    _logger.LogTrace($"Response for Event Call was {response.StatusCode}");
                    if (!response.IsSuccessStatusCode)
                    {
                        return(new List <SubscribedDomainEventWrapper>());
                    }
                    var content = await response.Content.ReadAsStringAsync();

                    var eventsByTypeAsync = _eventFactory.Deserialize(content).ToList();
                    _logger.LogTrace($"Retrieved {eventsByTypeAsync.Count} events");
                    return(eventsByTypeAsync);
                }
                _logger.LogTrace("Base Address not found, call avoided");
            }
            catch (HttpRequestException e)
            {
                var type      = typeof(T);
                var readModel = type.GenericTypeArguments.Single();
                _logger.LogWarning(e, $"Could not reach service for: {readModel.Name}");
            }

            return(new List <SubscribedDomainEventWrapper>());
        }