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.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 IDisposable Subscribe(IObserver <T> observer) { _observer = observer; _subscription = _connection.SubscribeToAllFrom(_lastCheckpoint, _resolveLinkTos, EventAppeared, subscriptionDropped: SubscriptionDropped); return(Disposable.Create(Stop)); }
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); }
//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 }
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 void Start() { var lastCheckpoint = LoadLastCheckpoint(); _subscription = _connection.SubscribeToAllFrom( lastCheckpoint, false, OnEventAppeared, OnLiveProcessingStarted, OnSubscriptionDropped); }
public void Start() { _subscription = _getConn().SubscribeToAllFrom( Position.Start, CatchUpSubscriptionSettings.Default, GotEvent, (_) => { _isLive = true; } ); SpinWait.SpinUntil(() => _isLive); UpdateSubscribers(); }
public Task Start() { var settings = new CatchUpSubscriptionSettings(2000, 500, false, false, _name); _subscription = _connection.SubscribeToAllFrom( AllCheckpoint.AllStart, settings, EventAppeared ); return(Task.CompletedTask); }
public void Start(IEventStoreConnection connection, IEnumerable <object> observers) { WireUpObservers(observers); var credentials = new UserCredentials(_applicationSettings.GesUserName, _applicationSettings.GesPassword); var lastCheckpoint = Position.Start; _subscription = connection.SubscribeToAllFrom(lastCheckpoint, false, EventAppeared, OnLiveProcessingStarted, OnSubscriptionDropped, credentials ); }
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 async Task StartAsync(CancellationToken cancellationToken) { var settings = new CatchUpSubscriptionSettings( maxLiveQueueSize: 10000, readBatchSize: 500, verboseLogging: false, resolveLinkTos: false, subscriptionName: "Tasks"); subscription = _eventStore.SubscribeToAllFrom( lastCheckpoint: null, settings: settings, eventAppeared: (sub, @event) => { if (@event.OriginalEvent.EventType.StartsWith("$")) { return; } try { var str = Encoding.UTF8.GetString(@event.OriginalEvent.Metadata); var ass = Assembly.Load("HelloWebApi"); var eventType = ass.GetType(str); var eventData = JsonSerializer.Deserialize(Encoding.UTF8.GetString(@event.OriginalEvent.Data), eventType); if (eventType != typeof(CreatedTask) && eventType != typeof(AssignedTask) && eventType != typeof(MovedTask) && eventType != typeof(CompletedTask)) { return; } System.Console.WriteLine("**************************************************"); Console.WriteLine(eventData); System.Console.WriteLine("**************************************************"); Console.WriteLine(Println(eventData)); } catch (Exception exception) { _logger.LogError(exception, exception.Message); } }, liveProcessingStarted: (sub) => { _logger.LogInformation("{SubscriptionName} subscription started.", sub.SubscriptionName); }, subscriptionDropped: (sub, subDropReason, exception) => { _logger.LogWarning("{SubscriptionName} dropped. Reason: {SubDropReason}.", sub.SubscriptionName, subDropReason); }); }
public async Task StartAsync(CancellationToken cancellationToken) { var lastCheckpoint = await _checkpointRepository.GetAsync("tasks"); var settings = new CatchUpSubscriptionSettings( maxLiveQueueSize: 10000, readBatchSize: 500, verboseLogging: false, resolveLinkTos: false, subscriptionName: "Tasks"); subscription = _eventStore.SubscribeToAllFrom( lastCheckpoint: lastCheckpoint, settings: settings, eventAppeared: async(sub, @event) => { 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(CreatedTask) && eventType != typeof(AssignedTask) && eventType != typeof(MovedTask) && eventType != typeof(CompletedTask)) { return; } _taskRepository.Save(eventData); await _checkpointRepository.SaveAsync("tasks", @event.OriginalPosition.GetValueOrDefault()); } catch (Exception exception) { _logger.LogError(exception, exception.Message); } }, liveProcessingStarted: (sub) => { _logger.LogInformation("{SubscriptionName} subscription started.", sub.SubscriptionName); }, subscriptionDropped: (sub, subDropReason, exception) => { _logger.LogWarning("{SubscriptionName} dropped. Reason: {SubDropReason}.", sub.SubscriptionName, subDropReason); }); }
static void Main() { WireObservers(); var credentials = new UserCredentials("admin", "changeit"); var connection = GetEventStoreConnection(); _subscription = connection.SubscribeToAllFrom(Position.Start, false, EventAppeared, OnLiveProcessingStarted, OnSubscriptionDropped, credentials); Console.WriteLine("Hit <enter> to exit:"); Console.ReadLine(); }
private void Subscribe() { if (_currentConnection == null) { return; } _subscription?.Stop(); _subscription = _currentConnection.SubscribeToAllFrom( _lastPosition, CatchUpSubscriptionSettings.Default, EventAppeared, LiveProcessingStarted, SubscriptionDropped ); }
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) { Ensure.NotNull(eventAppeared, "eventAppeared"); Ensure.NotNull(settings, "settings"); var catchUpSubscription = new EventStoreAllCatchUpSubscription(this, Settings.Log, lastCheckpoint, userCredentials, eventAppeared, liveProcessingStarted, subscriptionDropped, settings); catchUpSubscription.StartAsync(); return catchUpSubscription; }
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) { Ensure.NotNull(eventAppeared, "eventAppeared"); var catchUpSubscription = new EventStoreAllCatchUpSubscription(this, _settings.Log, lastCheckpoint, resolveLinkTos, userCredentials, eventAppeared, liveProcessingStarted, subscriptionDropped, _settings.VerboseLogging, readBatchSize); catchUpSubscription.Start(); return(catchUpSubscription); }
public async Task Start() { var settings = new CatchUpSubscriptionSettings( 2000, 500, Log.IsEnabled(LogEventLevel.Verbose), false, "try-out-subscription" ); Log.Debug("Starting the projection manager..."); var position = await _checkpointStore.GetCheckpoint(); Log.Debug("Retrieved the checkpoint: {checkpoint}", position); _subscription = _connection.SubscribeToAllFrom( position, settings, EventAppeared ); Log.Debug("Subscribed to $all stream"); }
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); _subscription = _connection.SubscribeToAllFrom(position, settings, EventAppeared, LiveProcessingStarted, SubscriptionDropped ); _log.Information("Subscribed to $all stream"); }
private void StartNewSubscriptionEpoch() { Task.Run(() => { lock (_subscriptionModificationLock) { if (_subscriptionTerminatedRequested) { return; } BeforeSubscriptionEpochStarts(); StopSubscriptionEpoch(); Interlocked.Increment(ref _subscriptionEpoch); var subscriptionSettings = new CatchUpSubscriptionSettings( maxLiveQueueSize: 500, readBatchSize: _settings.ReadBatchSize, verboseLogging: false, resolveLinkTos: _settings.ResolveLinkEvents, subscriptionName: SubscriptionName); Log.Information("Starting a new subscription epoch {Epoch} from commit position {LastCommitPosition} with name {Name}", _subscriptionEpoch, LastCommitPosition, SubscriptionName); _catchUpSubscription = Connection.SubscribeToAllFrom( lastCheckpoint: new Position(LastCommitPosition, LastCommitPosition), settings: subscriptionSettings, eventAppeared: EventAppeared, liveProcessingStarted: LiveProcessingStarted, subscriptionDropped: SubscriptionDropped); } }); }
public void StartDispatching() { _stopRequested = false; _subscription = _gesConnection.SubscribeToAllFrom(Position.Start, false, HandleNewEvent, null, null, new UserCredentials("admin", "changeit")); }
public override async Task StartAsync(CancellationToken cancellationToken) { if (!await _elasticSearchService.CheckIndex(ElasticSearchIndexDocumentNames.EmployeeIndexName)) { await _elasticSearchService.CretaeIndex <ProductViewModel>(ElasticSearchIndexDocumentNames.EmployeeIndexName, ElasticSearchIndexDocumentNames.EmployeeIndexAliasName); } var lastCheckpoint = await new CreateAndUpdatePointDocumentIndex(_elasticSearchService).addPointDocument( ElasticSearchIndexDocumentNames.EmployeeDocumentPositionIndexName, ElasticSearchIndexDocumentNames.EmployeeDocumentPositionAliasName, ElasticSearchIndexDocumentNames.EmployeeDocumentPositionName); var settings = new CatchUpSubscriptionSettings( maxLiveQueueSize: 10000, readBatchSize: 500, verboseLogging: false, resolveLinkTos: false, subscriptionName: "employee"); subscription = _eventStore.SubscribeToAllFrom( lastCheckpoint: lastCheckpoint, settings: settings, eventAppeared: async(sub, @event) => { if (@event.OriginalEvent.EventType.StartsWith("$")) { return; } try { var eventType = Type.GetType(Encoding.UTF8.GetString(@event.OriginalEvent.Metadata) + ",NorthwindApi.Domain"); var eventData = Newtonsoft.Json.JsonConvert.DeserializeObject(Encoding.UTF8.GetString(@event.OriginalEvent.Data), eventType); if (eventType != typeof(EmployeeAddEvent) && eventType != typeof(EmployeeUpdateEvent) && eventType != typeof(EmployeeRemoveEvent)) { return; } var eventSaveData = CreateViewModel(eventData); if (eventType == typeof(EmployeeAddEvent) || eventType == typeof(EmployeeUpdateEvent)) { await _elasticSearchService.AddOrUpdateIndex <EmployeeViewModel>(ElasticSearchIndexDocumentNames.EmployeeIndexName, ElasticSearchIndexDocumentNames.EmployeeIndexAliasName, eventSaveData); } else { await _elasticSearchService.Delete <EmployeeViewModel>(ElasticSearchIndexDocumentNames.EmployeeIndexName, eventSaveData.Id); } await new CreateAndUpdatePointDocumentIndex(_elasticSearchService).UpdatePointDocument( ElasticSearchIndexDocumentNames.EmployeeDocumentPositionIndexName, ElasticSearchIndexDocumentNames.EmployeeDocumentPositionAliasName, ElasticSearchIndexDocumentNames.EmployeeDocumentPositionName, @event.OriginalPosition.GetValueOrDefault()); } catch (Exception exception) { _logger.LogError(exception, exception.Message); } }, liveProcessingStarted: (sub) => { _logger.LogInformation("{SubscriptionName} subscription started.", sub.SubscriptionName); }, subscriptionDropped: (sub, subDropReason, exception) => { _logger.LogWarning("{SubscriptionName} dropped. Reason: {SubDropReason}.", sub.SubscriptionName, subDropReason); }); }
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) { Ensure.NotNull(eventAppeared, "eventAppeared"); var catchUpSubscription = new EventStoreAllCatchUpSubscription(this, _settings.Log, lastCheckpoint, resolveLinkTos, GetUserCredentials(_settings, userCredentials), eventAppeared, liveProcessingStarted, subscriptionDropped, _settings.VerboseLogging, readBatchSize); catchUpSubscription.Start(); return catchUpSubscription; }
private void Subscribe(Position position) { _allCatchUpSubscription = _originConnection.SubscribeToAllFrom(position, BuildSubscriptionSettings(), EventAppeared, LiveProcessingStarted, SubscriptionDropped); _logger.Debug($"Subscribed from position: {position}"); }
public void Start() { _subscription = _connection.SubscribeToAllFrom(Position.Start, true, EventAppeared); _subscription.Start(); }
public void Unsubscribe() { _subscription?.Stop(); _subscription = null; }
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; }