Example #1
0
 public PersistentSubscriptionParams(bool resolveLinkTos, string subscriptionId,
                                     IPersistentSubscriptionEventSource eventSource,
                                     string groupName,
                                     IPersistentSubscriptionStreamPosition startFrom,
                                     bool extraStatistics, TimeSpan messageTimeout,
                                     int maxRetryCount, int liveBufferSize, int bufferSize, int readBatchSize,
                                     TimeSpan checkPointAfter, int minCheckPointCount,
                                     int maxCheckPointCount, int maxSubscriberCount,
                                     IPersistentSubscriptionConsumerStrategy consumerStrategy,
                                     IPersistentSubscriptionStreamReader streamReader,
                                     IPersistentSubscriptionCheckpointReader checkpointReader,
                                     IPersistentSubscriptionCheckpointWriter checkpointWriter,
                                     IPersistentSubscriptionMessageParker messageParker)
 {
     _resolveLinkTos     = resolveLinkTos;
     _subscriptionId     = subscriptionId;
     _eventSource        = eventSource;
     _groupName          = groupName;
     _startFrom          = startFrom;
     _extraStatistics    = extraStatistics;
     _messageTimeout     = messageTimeout;
     _maxRetryCount      = maxRetryCount;
     _liveBufferSize     = liveBufferSize;
     _bufferSize         = bufferSize;
     _checkPointAfter    = checkPointAfter;
     _minCheckPointCount = minCheckPointCount;
     _maxCheckPointCount = maxCheckPointCount;
     _maxSubscriberCount = maxSubscriberCount;
     _consumerStrategy   = consumerStrategy;
     _readBatchSize      = readBatchSize;
     _streamReader       = streamReader;
     _checkpointReader   = checkpointReader;
     _checkpointWriter   = checkpointWriter;
     _messageParker      = messageParker;
 }
Example #2
0
 public void BeginReadEvents(IPersistentSubscriptionEventSource eventSource,
                             IPersistentSubscriptionStreamPosition startPosition, int countToLoad, int batchSize, bool resolveLinkTos,
                             bool skipFirstEvent,
                             Action <ResolvedEvent[], IPersistentSubscriptionStreamPosition, bool> onEventsFound, Action <string> onError)
 {
     BeginReadEventsInternal(eventSource, startPosition, countToLoad, batchSize, resolveLinkTos,
                             skipFirstEvent, onEventsFound, onError, 0);
 }
Example #3
0
        private void BeginReadEventsInternal(IPersistentSubscriptionEventSource eventSource,
                                             IPersistentSubscriptionStreamPosition startPosition, int countToLoad, int batchSize, bool resolveLinkTos, bool skipFirstEvent,
                                             Action <ResolvedEvent[], IPersistentSubscriptionStreamPosition, bool> onEventsFound, Action <string> onError, int retryCount)
        {
            var actualBatchSize = GetBatchSize(batchSize);

            if (eventSource.FromStream)
            {
                _ioDispatcher.ReadForward(
                    eventSource.EventStreamId, startPosition.StreamEventNumber, Math.Min(countToLoad, actualBatchSize),
                    resolveLinkTos, SystemAccounts.System, new ResponseHandler(onEventsFound, onError, skipFirstEvent).FetchCompleted,
                    async() => {
                    var backOff = GetBackOffDelay(retryCount);
                    Log.Warning("Timed out reading from stream: {stream}. Retrying in {retryInterval} seconds.", eventSource.EventStreamId, backOff);
                    await Task.Delay(TimeSpan.FromSeconds(backOff)).ConfigureAwait(false);
                    BeginReadEventsInternal(eventSource, startPosition, countToLoad, batchSize, resolveLinkTos,
                                            skipFirstEvent, onEventsFound, onError, retryCount + 1);
                }, Guid.NewGuid());
            }
            else if (eventSource.FromAll)
            {
                _ioDispatcher.ReadAllForward(
                    startPosition.TFPosition.Commit,
                    startPosition.TFPosition.Prepare,
                    Math.Min(countToLoad, actualBatchSize),
                    resolveLinkTos,
                    true,
                    null,
                    SystemAccounts.System,
                    null,
                    new ResponseHandler(onEventsFound, onError, skipFirstEvent).FetchAllCompleted,
                    async() => {
                    var backOff = GetBackOffDelay(retryCount);
                    Log.Warning("Timed out reading from stream: {stream}. Retrying in {retryInterval} seconds.", SystemStreams.AllStream, backOff);
                    await Task.Delay(TimeSpan.FromSeconds(backOff)).ConfigureAwait(false);
                    BeginReadEventsInternal(eventSource, startPosition, countToLoad, batchSize, resolveLinkTos,
                                            skipFirstEvent, onEventsFound, onError, retryCount + 1);
                }, Guid.NewGuid());
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
 /// <summary>
 /// Sets the event source of the subscription
 /// </summary>
 /// <param name="eventSource"></param>
 /// <returns></returns>
 public PersistentSubscriptionParamsBuilder WithEventSource(IPersistentSubscriptionEventSource eventSource)
 {
     _eventSource = eventSource;
     return(this);
 }