예제 #1
0
        private void PollFromHttp(string streamType, string url, string token, long fromVersion)
        {
            using (var httpClient = this.CreateHttpClient(token))
            {
                var dynamicUrl = $"{url}/{fromVersion}/{this.pollerName}";
                try
                {
                    var result = httpClient.GetAsync(dynamicUrl).Result;
                    if (!result.IsSuccessStatusCode)
                    {
                        throw new InvalidOperationException(string.Format("The status code was: {0}", result.StatusCode.ToString()));
                    }

                    var response = result.Content.ReadAsAsync <PollResponse>().Result;

                    this.PublishPollResponse(response);
                }
                catch (Exception ex)
                {
                    this.log.Error(ex, $"Error while polling {streamType} located on {dynamicUrl}");
                    this.log.Trace($"An error has been detected while polling {streamType} located on {dynamicUrl} but a retry will be performed every 10 seconds");

                    // To have a break;
                    Thread.Sleep(10000);
                    this.bus.Publish(new PollResponseWasReceived(PollResponse.CreateErrorResponse(streamType)));
                }
            }
        }
예제 #2
0
        private static PollResponse CreateBaseResponse(bool errorDetected, bool newEventsWereFound, string streamType, long consumerVersion, long producerVersion)
        {
            var response = new PollResponse();

            response.NewEventsWereFound = newEventsWereFound;
            response.StreamType         = streamType;
            response.ErrorDetected      = errorDetected;

            // Metrics
            response.ConsumerVersion = consumerVersion;
            response.ProducerVersion = producerVersion;
            return(response);
        }
        public bool TryUpdateConsumer(string consumerName, PollResponse response, out ServerStatus status)
        {
            status = null;
            if (!this.ocassionallyConnectedSourcesByConsumer.ContainsKey(consumerName))
                return false;

            var sources = this.ocassionallyConnectedSourcesByConsumer[consumerName];
            if (!sources.ContainsKey(response.StreamType))
                return false;

            var consumer = sources[response.StreamType];
            lock (consumer)
            {
                status = consumer.UpdateConsumer(response);
            }
            return true;
        }
예제 #4
0
        private static PollResponse CreateBaseResponse(bool errorDetected, bool newEventsWereFound, string streamType, long consumerVersion, long producerVersion)
        {
            var response = new PollResponse();
            response.NewEventsWereFound = newEventsWereFound;
            response.StreamType = streamType;
            response.ErrorDetected = errorDetected;

            // Metrics
            response.ConsumerVersion = consumerVersion;
            response.ProducerVersion = producerVersion;
            return response;
        }
 public PollResponseWasReceived(PollResponse response)
 {
     this.Response = response;
 }
예제 #6
0
 private void PublishPollResponse(PollResponse response)
 {
     this.bus.Publish(new PollResponseWasReceived(response));
 }
예제 #7
0
 private void PublishPollResponse(PollResponse response)
 {
     this.bus.Publish(new PollResponseWasReceived(response));
 }
        public ServerStatus UpdateConsumer(PollResponse producerResponse)
        {
            if (this.consumerEventCollectionVersion == producerResponse.ConsumerVersion) // only updates if versions are equal. Nasty errors.
            {
                var ecvBefore = this.consumerEventCollectionVersion;

                this.producerResponse.Add(producerResponse);

                var stopwatch = Stopwatch.StartNew();
                while (this.consumerEventCollectionVersion == ecvBefore && this.pusherTimeout > stopwatch.Elapsed)
                    Thread.Sleep(1);
            }

            return new ServerStatus(this.consumerEventCollectionVersion);
        }