static void Main(string[] args) { system = ActorSystem.Create("test"); var routerProps = Props .Create <EventRouterActor>(); router = system.ActorOf(routerProps, "router"); var connectionSettings = ConnectionSettings.Create(); connectionSettings.KeepRetrying(); connectionSettings.KeepReconnecting(); connectionSettings.SetDefaultUserCredentials(new UserCredentials("admin", "changeit")); var eventStoreEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1112); var Connection = EventStoreConnection.Create(connectionSettings.Build(), eventStoreEndpoint); Connection.ConnectAsync().Wait(); var subscriptionSettings = new CatchUpSubscriptionSettings(200 * 4096, 4096, false, false); var esSubscription = Connection.SubscribeToAllFrom( new Position(StreamPosition.Start, StreamPosition.Start), subscriptionSettings, ConsumerEventAppeared, LiveProcessingStarted, SubscriptionDropped ); start = DateTime.Now; while (Console.ReadKey().KeyChar != 'q') { } }
public async Task Start() { var settings = new CatchUpSubscriptionSettings( 2000, 500, Log.IsDebugEnabled(), false, _name ); Log.Debug("Starting the projection manager..."); var position = await _checkpointStore.GetCheckpoint(); Log.Debug("Retrieved the checkpoint: {checkpoint}", position); _subscription = _connection.SubscribeToAllFrom( GetPosition(), settings, EventAppeared ); Log.Debug("Subscribed to $all stream"); Position?GetPosition() => position.HasValue ? new Position(position.Value, position.Value) : AllCheckpoint.AllStart; }
public async Task <EventStoreCatchUpSubscription> Subscribe(IEventStoreConnection connection) { var settings = new CatchUpSubscriptionSettings(10000, 500, false, true, _name); var position = await _checkpointStore.Load(_name); return(connection.SubscribeToAllFrom(position, settings, EventAppeared)); async Task EventAppeared(EventStoreCatchUpSubscription _, ResolvedEvent resolvedEvent) { if (resolvedEvent.IsSystemEvent()) { return; } try { var streamEvent = resolvedEvent.Deserialize(); var subscription = (EventStoreAllCatchUpSubscription)_; await Task.WhenAll(_handlers.Select(x => x(streamEvent))); await _checkpointStore.Store(_name, subscription.LastProcessedPosition); } catch (Exception e) { Logger.Error(e, "Error occured while handling {@event}", resolvedEvent); } } }
public void Start() { var settings = new CatchUpSubscriptionSettings(2000, 500, true, true, "try-out-subscription"); subscription = storeConnection.SubscribeToAllFrom( Position.Start, settings, EventAppeared, LiveSubscriptionStarted, SubscriptionDropped); }
public async Task Start() { var settings = new CatchUpSubscriptionSettings( 2000 , 500 , _log.IsEnabled(LogEventLevel.Debug) , false); _log.Information("Starting the subscription manager..."); var position = await _checkpointStore.GetCheckpoint(); _log.Information("Retrieved the checkpoint: {checkpoint}", position); var _subscription = _connection.SubscribeToAllFrom(position , settings , EventAppeared , LiveProcessingStarted , SubscriptionDropped); // var _subscription = _connection.SubscribeToStreamFrom("$all" // ,position.Value.CommitPosition // , settings // , EventAppeared // , LiveProcessingStarted // , SubscriptionDropped); _log.Information("Subscribed to $all stream"); }
private void SetupSubscription(IComponentContext c, IEventStoreConnection esConnection) { var freshContext = c.Resolve <IComponentContext>(); long? lastPosition; string stream = "nalozi"; using (var scope = freshContext.Resolve <ILifetimeScope>().BeginLifetimeScope()) { var processedRepo = scope.Resolve <IProcessedEventRepository>(); var lastEvent = processedRepo.GetLastProcessed(stream); lastPosition = lastEvent?.Checkpoint; } var options = freshContext.Resolve <IOptions <AppSettings> >(); var catchUpSettings = new CatchUpSubscriptionSettings(options.Value.EventStoreMaxQueueSize, options.Value.EventStoreReadBatchSize, true, true); esConnection.SubscribeToStreamFrom(stream, lastPosition, catchUpSettings, eventAppeared: async(s, e) => { using (var scope = freshContext.Resolve <ILifetimeScope>().BeginLifetimeScope()) { var eventHandler = scope.Resolve <Persistence.IEventHandler>(); await eventHandler.HandleAsync(e); } }, liveProcessingStarted: null, subscriptionDropped: (sub, reason, exc) => { sub.Stop(); var conn = freshContext.Resolve <IEventStoreConnection>(); SetupSubscription(freshContext, conn); }, userCredentials: new UserCredentials(options.Value.EVENTSTORE_USERNAME, options.Value.EVENTSTORE_PASSWORD)); }
public Task <bool> SubscribeToStreamStart(string stream, CancellationToken token, Action <string, long, IFullEvent> callback, Func <Task> disconnected) { var clientsToken = CancellationTokenSource.CreateLinkedTokenSource(token); foreach (var client in _clients) { Logger.Write(LogLevel.Info, () => $"Subscribing to beginning of stream [{stream}] on client {client.Settings.GossipSeeds[0].EndPoint.Address}"); var settings = new CatchUpSubscriptionSettings(1000, 50, Logger.IsDebugEnabled, true); var startingNumber = 0L; try { var subscription = client.SubscribeToStreamFrom(stream, startingNumber, settings, eventAppeared: (sub, e) => EventAppeared(sub, e, clientsToken.Token, callback), subscriptionDropped: (sub, reason, ex) => SubscriptionDropped(sub, reason, ex, disconnected)); Logger.Write(LogLevel.Info, () => $"Subscribed to stream [{stream}] on client {client.Settings.GossipSeeds[0].EndPoint.Address}"); lock (_subLock) _subscriptions.Add(subscription); } catch (OperationTimedOutException) { // If one fails, cancel all the others clientsToken.Cancel(); } } return(Task.FromResult(!clientsToken.IsCancellationRequested)); }
internal void Subscribe(StreamId streamId, Func <Checkpoint> checkpoint, CatchUpSubscriptionSettings settings, Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> eventAppeared, Action <EventStoreCatchUpSubscription> liveProcessingStarted = null, Action <SubscriptionDropReason, Exception> subscriptionDropped = null) { _currentSubscription = new CurrentSubscription(streamId, checkpoint, settings, eventAppeared, liveProcessingStarted, subscriptionDropped); if (Equals(streamId, StreamId.All)) { SubscribeToAll(checkpoint, settings, eventAppeared, liveProcessingStarted, subscriptionDropped); } else { SubscribeToStream(streamId, checkpoint, settings, eventAppeared, liveProcessingStarted, subscriptionDropped); } }
public void SetUp() { _connection = new FakeEventStoreConnection(); _raisedEvents = new List <ResolvedEvent>(); _dropEvent = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _raisedEventEvent = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _liveProcessingStarted = false; _isDropped = false; _dropReason = SubscriptionDropReason.Unknown; _dropException = null; var settings = new CatchUpSubscriptionSettings(1, 1, false, false, String.Empty); _subscription = new EventStoreStreamCatchUpSubscription(_connection, new NoopLogger(), StreamId, null, null, (subscription, ev) => { _raisedEvents.Add(ev); if (_raisedEvents.Count >= 2) { _raisedEventEvent.TrySetResult(true); } return(Task.CompletedTask); }, subscription => { _liveProcessingStarted = true; }, (subscription, reason, ex) => { _isDropped = true; _dropReason = reason; _dropException = ex; _dropEvent.TrySetResult(true); }, settings); }
public void SetUp() { _connection = new FakeEventStoreConnection(); _raisedEvents = new List <ResolvedEvent>(); _dropEvent = new ManualResetEventSlim(); _raisedEventEvent = new ManualResetEventSlim(); _liveProcessingStarted = false; _isDropped = false; _dropReason = SubscriptionDropReason.Unknown; _dropException = null; var settings = new CatchUpSubscriptionSettings(1, 1, false, false, String.Empty); _subscription = new EventStoreStreamCatchUpSubscription(_connection, new NoopLogger(), StreamId, null, null, (subscription, ev) => { _raisedEvents.Add(ev); _raisedEventEvent.Set(); return(Task.CompletedTask); }, subscription => { _liveProcessingStarted = true; }, (subscription, reason, ex) => { _isDropped = true; _dropReason = reason; _dropException = ex; _dropEvent.Set(); }, settings); }
private void StartCatchUpSubscription(Position?startPosition) { lock (LockObj) { _eventBuffer = new EventBuffer(_batchSize + 28); } _onCompletedFired = false; _isStarted = true; var settings = new CatchUpSubscriptionSettings(_maxLiveQueueMessage, _batchSize, true, false); if (startPosition == null) { var slice = _connection.Value.ReadAllEventsBackwardAsync(Position.End, 1, false, _userCredentials).Result; _lastAllPosition = slice.FromPosition; } _subscription = _connection.Value.SubscribeToAllFrom( startPosition ?? AllCheckpoint.AllStart, settings, EventAppeared, LiveProcessingStarted, SubscriptionDropped, _userCredentials); _trace.Info($"Catch-up subscription started from checkpoint {startPosition} at {DateTime.Now}."); }
public void Start() { var settings = new CatchUpSubscriptionSettings(2000, 500, Log.IsEnabled(Serilog.Events.LogEventLevel.Verbose), false, "try-out-subscription"); subscription = connection.SubscribeToAllFrom(Position.Start, settings, EventAppeared); }
public ISubscription SubscribeToAllFrom(IPosition lastCheckPoint, Func <ISubscription, IEventData, Task> onEventAppeared, Action <ISubscription> onLiveProcessingStarted = null, Action <ISubscription, string, Exception> onSubscriptionDropped = null, IUserCredentials userCredentials = null, int batchSize = 512) { var effectiveCheckPoint = lastCheckPoint == null ? global::EventStore.ClientAPI.Position.Start : ((Position)lastCheckPoint).Value; var userCreds = userCredentials == null ? null : new global::EventStore.ClientAPI.SystemData.UserCredentials(userCredentials.Username, userCredentials.Password); onLiveProcessingStarted = onLiveProcessingStarted ?? ((s) => { }); onSubscriptionDropped = onSubscriptionDropped ?? ((s, r, e) => { }); var settings = new CatchUpSubscriptionSettings(MAX_LIVE_QUEUE_SIZE, READ_BATCH_SIZE, false, true); var subscriptionId = Guid.NewGuid().ToString(); var esSubscription = _connection.SubscribeToAllFrom(effectiveCheckPoint, settings, async(_, ev) => await onEventAppeared(_subscriptions[subscriptionId], FromDb(ev)), (_) => onLiveProcessingStarted(_subscriptions[subscriptionId]), (_, reason, ex) => onSubscriptionDropped(_subscriptions[subscriptionId], reason.ToString(), ex), userCreds); var subscription = _subscriptions[subscriptionId] = new CatchupSubscription(esSubscription); return(subscription); }
public IDisposable SubscribeToAllFrom( Position from, Action <RecordedEvent> eventAppeared, CatchUpSubscriptionSettings settings = null, Action liveProcessingStarted = null, Action <SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials userCredentials = null, bool resolveLinkTos = true) { var sub = EsConnection.SubscribeToAllFrom( new ES.Position(from.CommitPosition, from.PreparePosition), settings?.ToCatchUpSubscriptionSettings(), async(_, evt) => { eventAppeared(evt.Event.ToRecordedEvent()); await Task.FromResult(Unit.Default); }, __ => { liveProcessingStarted?.Invoke(); }, (_, reason, ex) => subscriptionDropped?.Invoke((SubscriptionDropReason)(int)reason, ex), userCredentials?.ToESCredentials()); return(new Disposer(() => { sub.Stop(TimeSpan.FromMilliseconds(250)); return Unit.Default; })); }
public IDisposable SubscribeToStreamFrom( string stream, long?lastCheckpoint, bool resolveLinkTos, Action <Message> eventAppeared, Action liveProcessingStarted = null, Action <SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials userCredentials = null, int readBatchSize = 500) { var settings = new CatchUpSubscriptionSettings(10, readBatchSize, false); StreamName = stream; var sub = _eventStoreConnection.SubscribeToStreamFrom( stream, lastCheckpoint, settings, resolvedEvent => { Interlocked.Exchange(ref _position, resolvedEvent.EventNumber); eventAppeared(_serializer.Deserialize(resolvedEvent) as Message); }, _ => liveProcessingStarted?.Invoke(), (reason, exception) => subscriptionDropped?.Invoke(reason, exception), userCredentials); return(new Disposer(() => { sub.Dispose(); return Unit.Default; })); }
public Task <bool> SubscribeToStreamStart(string stream, CancellationToken token, Func <string, long, IFullEvent, Task> callback, Func <Task> disconnected) { var clientsToken = CancellationTokenSource.CreateLinkedTokenSource(token); foreach (var client in _clients) { Logger.InfoEvent("BeginSubscribe", "[{Stream:l}] store {Store}", stream, client.Settings.GossipSeeds[0].EndPoint); var settings = new CatchUpSubscriptionSettings(1000, 50, Logger.IsDebugEnabled(), true); var startingNumber = 0L; try { var subscription = client.SubscribeToStreamFrom(stream, startingNumber, settings, eventAppeared: (sub, e) => EventAppeared(sub, e, clientsToken.Token, callback), subscriptionDropped: (sub, reason, ex) => SubscriptionDropped(sub, reason, ex, disconnected, clientsToken.Token)); lock (_subLock) _subscriptions.Add(subscription); } catch (OperationTimedOutException) { // If one fails, cancel all the others clientsToken.Cancel(); } } return(Task.FromResult(!clientsToken.IsCancellationRequested)); }
private async Task StartProjection(Projection projection) { var lastCheckpoint = await _checkpointStore.GetLastCheckpoint <Position>(projection); var settings = new CatchUpSubscriptionSettings(10000, 500, true, false, projection); _connection.SubscribeToAllFrom(lastCheckpoint, settings, EventAppeared(projection)); }
internal SubscribeCommand( EventStoreContext context, CatchUpSubscriptionSettings settings, ITimelineObserver observer) { _context = context; _settings = settings; _observer = observer; }
//creates and connects to a new CatchUp subscription public void Start() { var settings = new CatchUpSubscriptionSettings(2000, 500, Log.IsEnabled(LogEventLevel.Verbose), false, "try-out-subscription"); _subscription = _connection.SubscribeToAllFrom(Position.Start, //will get all events from the beginning of stream (catch up), subscribes to the $all stream settings, EventAppeared); //delegate that is called for each event }
private async Task StartProjection(Projection projection) { var lastCheckpoint = await checkpointStore.GetLastCheckpoint <Position>(projection); var catchUpSubscriptionSettings = new CatchUpSubscriptionSettings(maxLiveQueueSize, readBatchSize, verboseLogging, false, projection); eventStoreConnection.SubscribeToAllFrom(lastCheckpoint, catchUpSubscriptionSettings, eventAppeared(projection), liveProcessingStarted(projection), subscriptionDropped(projection), userCredentials); }
public async Task Start() { var settings = new CatchUpSubscriptionSettings(2000, 500, Log.IsEnabled(LogEventLevel.Verbose), false, "try-out-subscription"); var position = await _checkpointStore.GetCheckpoint(); _subscription = _connection.SubscribeToAllFrom(position, settings, EventAppeared); }
public EventStoreAllCatchUpSubscription SubscribeToAllFrom( Position?lastCheckpoint, CatchUpSubscriptionSettings settings, Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> eventAppeared, Action <EventStoreCatchUpSubscription> liveProcessingStarted = null, Action <EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials userCredentials = null) { throw new NotImplementedException(); }
public TimelineSubscription( EventStoreContext context, CatchUpSubscriptionSettings settings, TimelinePosition checkpoint, ITimelineObserver observer) { _context = context; _settings = settings; _checkpoint = checkpoint; _observer = observer; }
public EventStoreStreamCatchUpSubscription SubscribeToStreamFrom( string stream, int?lastCheckpoint, CatchUpSubscriptionSettings settings, Action <EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared, Action <EventStoreCatchUpSubscription> liveProcessingStarted = null, Action <EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials userCredentials = null) { throw new NotImplementedException(); }
public bool Start(IDomainRepository domainRepository, IEventStoreConnection connection, IEnumerable <Action <ICommand> > preExecutionPipe = null, IEnumerable <Action <object> > postExecutionPipe = null) { _connection = connection; _domainEntry = new DomainEntry(domainRepository, preExecutionPipe, postExecutionPipe); _checkpointRepository = new EventStoreCheckpointRepository(connection, CheckpointId); _latestPosition = _checkpointRepository.Get(); var settings = new CatchUpSubscriptionSettings(10, 100, false, true); _connection.SubscribeToAllFrom(_latestPosition, settings, HandleEvent); Console.WriteLine("AppServiceStrategy started"); return(true); }
public void OneTimeSetUp() { _conn = BuildConnection(); _conn.ConnectAsync().Wait(); //Create 80000 events for (var i = 0; i < 80; i++) { _conn.AppendToStreamAsync(_streamName, ExpectedVersion.Any, CreateThousandEvents()).Wait(); } _settings = new CatchUpSubscriptionSettings(100, 1, false, true); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var settings = new CatchUpSubscriptionSettings(100, 100, false, true); var subscription = _connection.SubscribeToStreamFrom(EvelynEvents, null, settings, OnEventAppeared, OnLiveProcessingStarted, OnSubscriptionDropped); while (!stoppingToken.IsCancellationRequested) { await Task.Delay(TimeSpan.FromSeconds(1), stoppingToken); } subscription.Stop(); }
public Task Start() { var settings = new CatchUpSubscriptionSettings(2000, 500, false, false, _name); _subscription = _connection.SubscribeToAllFrom( AllCheckpoint.AllStart, settings, EventAppeared ); return(Task.CompletedTask); }
private IObservable <RecordedEvent> GetAllEvents(IEventStoreConnection connection) { return(Observable.Create <RecordedEvent>(o => { if (_log.IsEnabled(LogEventLevel.Information)) { _log.Information("Getting events from Event Store"); } Action <EventStoreCatchUpSubscription, ResolvedEvent> onEvent = (_, e) => { _eventLoopScheduler.Schedule(() => { o.OnNext(e.Event); }); }; Action <EventStoreCatchUpSubscription> onCaughtUp = evt => { _eventLoopScheduler.Schedule(() => { if (_log.IsEnabled(LogEventLevel.Information)) { _log.Information("Caught up to live events. Publishing State of The World"); } _isCaughtUp = true; _stateOfTheWorldContainer.IsStale = false; _stateOfTheWorldUpdates.OnNext(_stateOfTheWorldContainer); }); }; var subscriptionSettings = new CatchUpSubscriptionSettings( CatchUpSubscriptionSettings.Default.MaxLiveQueueSize, CatchUpSubscriptionSettings.Default.ReadBatchSize, CatchUpSubscriptionSettings.Default.VerboseLogging, false); var subscription = connection.SubscribeToAllFrom(Position.Start, subscriptionSettings, onEvent, onCaughtUp); var guid = Guid.Empty; if (_log.IsEnabled(LogEventLevel.Information)) { guid = Guid.NewGuid(); _log.Information("Subscribed to Event Store. Subscription ID {subscriptionId}", guid); } return Disposable.Create(() => { if (_log.IsEnabled(LogEventLevel.Information)) { _log.Information("Stopping Event Store subscription {subscriptionId}", guid); } subscription.Stop(); }); })); }
public async Task StartAsync(CancellationToken cancellationToken) { //eventler arasından en son kayıt getirilir. var lastTaskContentPosition = await _taskPositionRepository.FindAsync("TaskContent"); var settings = new CatchUpSubscriptionSettings( maxLiveQueueSize: 10000, readBatchSize: 500, verboseLogging: false, resolveLinkTos: false, subscriptionName: "TaskContent"); //ilgili event store'a subscribe olup eventler dinlenir, verilen son position değeri ile tekrar tekrar proje ayağa kalktığında eventleri gezmesini engelledik. _subscription = _eventStoreConnection.SubscribeToAllFrom( lastCheckpoint: lastTaskContentPosition?.Position, settings: settings, eventAppeared: async(sub, @event) => { //Event Store’un kendine ait event‘leri ile ilgili işlem yapmamak için pas geçiyoruz. if (@event.OriginalEvent.EventType.StartsWith("$")) { return; } try { var eventType = Type.GetType(Encoding.UTF8.GetString(@event.OriginalEvent.Metadata)); var eventData = JsonSerializer.Deserialize(Encoding.UTF8.GetString(@event.OriginalEvent.Data), eventType); if (eventType != typeof(AssignTaskModel) && eventType != typeof(ChangeTaskStatusModel) && eventType != typeof(CreateTaskModel)) { return; } Save(eventData); var doc = new TaskPosition { Id = "TaskContent", Key = "TaskContent", Position = @event.OriginalPosition.GetValueOrDefault() }; await _taskPositionRepository.UpsertAsync(doc); } catch (Exception exception) { _logger.LogError(exception, exception.Message); } }); }
public EventStoreAllCatchUpSubscription SubscribeToAllFrom( Position? lastCheckpoint, bool resolveLinkTos, Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared, Action<EventStoreCatchUpSubscription> liveProcessingStarted = null, Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials userCredentials = null, int readBatchSize = 500) { var settings = new CatchUpSubscriptionSettings(Consts.CatchUpDefaultMaxPushQueueSize, readBatchSize, _settings.VerboseLogging, resolveLinkTos); return SubscribeToAllFrom(lastCheckpoint, settings,eventAppeared, liveProcessingStarted, subscriptionDropped, userCredentials); }
public EventStoreAllCatchUpSubscription SubscribeToAllFrom( Position? lastCheckpoint, CatchUpSubscriptionSettings settings, Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared, Action<EventStoreCatchUpSubscription> liveProcessingStarted = null, Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null, UserCredentials userCredentials = null) { Ensure.NotNull(eventAppeared, "eventAppeared"); Ensure.NotNull(settings, "settings"); var catchUpSubscription = new EventStoreAllCatchUpSubscription(this, _settings.Log, lastCheckpoint, userCredentials, eventAppeared, liveProcessingStarted, subscriptionDropped, settings); catchUpSubscription.Start(); return catchUpSubscription; }