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 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); }
private void SubscribeMe() { //_conn.SubscribeToStreamFrom("$ce-domain", StreamCheckpoint.StreamStart, CatchUpSubscriptionSettings.Default, // EventAppeared, LiveProcessingStarted, SubscriptionDropped, _credentials); _conn.SubscribeToAllFrom(Position.Start, CatchUpSubscriptionSettings.Default, EventAppeared, LiveProcessingStarted, SubscriptionDropped, _credentials); }
public void Start(string connectionName) { eventStoreConnection = eventStoreConnectionFactory.Create(connectionName); var lastProcessedPosition = mongoDbEventPositionRepository.Get(); eventStoreConnection.SubscribeToAllFrom(lastProcessedPosition, false, (subs, re) => DispatchEvent(re.ToResolvedEventWrapper())); }
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); }
/// <inheritdoc /> public virtual async Task SubscribeAsync() { await _connection.ConnectAsync(); _connection.SubscribeToAllFrom(await GetCheckpointPosition(), CatchUpSubscriptionSettings.Default, EventAppeared(), LiveProcessingStarted(), SubscriptionDropped(), DefaultUserCredentials.Value); }
public IDisposable Subscribe(IObserver <T> observer) { _observer = observer; _subscription = _connection.SubscribeToAllFrom(_lastCheckpoint, _resolveLinkTos, EventAppeared, subscriptionDropped: SubscriptionDropped); return(Disposable.Create(Stop)); }
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 ConfigureProjections(IEventStoreConnection connection) { var projector = new SqlProjector( Resolve.WhenEqualToHandlerMessageType(new CustomerProjection()), new TransactionalSqlCommandExecutor( new ConnectionStringSettings( "projac", @"Data Source=.\SQLEXPRESS;Initial Catalog=Projections;Integrated Security=SSPI;", "System.Data.SqlClient"), IsolationLevel.ReadCommitted)); projector.Project(new object[] { new DropSchema(), new CreateSchema() }); var position = Position.Start; connection.SubscribeToAllFrom(position, false, (subscription, @event) => { object data = null; try { data = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(@event.Event.Data), Type.GetType(@event.Event.EventType, false)); } catch { // ignored } if (data != null) { projector.Project(data); } }); }
public void Start() { var settings = new CatchUpSubscriptionSettings(2000, 500, true, true, "try-out-subscription"); subscription = storeConnection.SubscribeToAllFrom( Position.Start, settings, EventAppeared, LiveSubscriptionStarted, SubscriptionDropped); }
private void ConnectToEventstore() { _latestPosition = Position.Start; _connection = EventStoreConnectionWrapper.Connect(); _connection.Connected += (sender, args) => _connection.SubscribeToAllFrom(_latestPosition, false, HandleEvent); Console.WriteLine("Indexing service started"); }
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)); }
//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 void Start() { _connection .SubscribeToAllFrom( Position.Start, CatchUpSubscriptionSettings.Default, Project ); }
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); }
void StartProjection(IProjection projection) { var checkpoint = GetPosition(projection.GetType()); _eventStoreConnection.SubscribeToAllFrom( checkpoint, CatchUpSubscriptionSettings.Default, EventAppeared(projection), LiveProcessingStarted(projection)); }
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); }
static void Main(string[] args) { eventMaps(); eventStoreConnection = EventStoreConnection.Create(new Uri("tcp://*****:*****@127.0.0.1:1113"), "Fix-App"); eventStoreConnection.ConnectAsync(); eventStoreConnection.SubscribeToAllFrom(new Position(0L, 0L), CatchUpSubscriptionSettings.Default, EventAppeared); Console.WriteLine("Let me fix mate!"); Console.ReadKey(); }
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); }
private void Subscribe(Position position) { this.isLive = false; this.lastPositionString = position.ToString(); connection.SubscribeToAllFrom( position, new CatchUpSubscriptionSettings(100, 650, true, true), this.EventAppeared, this.LiveProcessingStarted ); }
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 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 void Start() { HasLoaded = false; _connection = EventStore.ClientAPI.EventStoreConnection.Create(_endpoint); var ct = _connection.ConnectAsync(); ct.Wait(); _checkPoint = Position.Start; if (string.IsNullOrEmpty(_streamName)) _subscription = _connection.SubscribeToAllFrom(_checkPoint, false, EventAppeared, Live, SubscriptionDropped, _credentials); else _subscription = _connection.SubscribeToStreamFrom(_streamName, _lastEventNumber, true, EventAppeared, Live, SubscriptionDropped, _credentials); }
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 void SubscribeToAll(string subscriptionName, Action <IDomainEvent> action) { Connection.SubscribeToAllFrom(Position.Start, CatchUpSubscriptionSettings.Default, (_, e) => { if (e.Event.EventStreamId[0] == '$') { return; } var domainEvent = DeserializeDomainEvent(e); action(domainEvent); }); }
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 void SubscribeToAll(String endpoint) { var saved = _store.Load(endpoint).Result; var readSize = _settings.Get <Int32>("ReadSize"); Logger.InfoFormat("Endpoint '{0}' subscribing to all events from position '{1}'", endpoint, saved); _client.SubscribeToAllFrom(saved, false, (subscription, e) => { Logger.DebugFormat("Event appeared position {0}", e.OriginalPosition?.CommitPosition); // Unsure if we need to care about events from eventstore currently if (!e.Event.IsJson) { return; } var descriptor = e.Event.Metadata.Deserialize(_jsonSettings); var data = e.Event.Data.Deserialize(e.Event.EventType, _jsonSettings); // Data is null for certain irrelevant eventstore messages (and we don't need to store position or snapshots) if (data == null) { return; } try { _dispatcher.Dispatch(data, descriptor, e.OriginalPosition?.CommitPosition); } catch (SubscriptionCanceled) { subscription.Stop(); throw; } }, liveProcessingStarted: (_) => { Logger.Info("Live processing started"); ProcessingLive = true; }, subscriptionDropped: (_, reason, e) => { Logger.WarnFormat("Subscription dropped for reason: {0}. Exception: {1}", reason, e); ProcessingLive = false; if (Dropped != null) { Dropped.Invoke(reason.ToString(), e); } }, readBatchSize: readSize); }
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); }); }
void SubscribeToAll(Func <Checkpoint> checkpoint, CatchUpSubscriptionSettings settings, Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> eventAppeared, Action <EventStoreCatchUpSubscription> liveProcessingStarted, Action <SubscriptionDropReason, Exception> subscriptionDropped) { _loggingAdaptor.Information("Subscribing to all stream starting at checkpoint {0}", checkpoint().ToString()); _eventStoreConnection.SubscribeToAllFrom(checkpoint().ToPosition(), settings, OnEventAppeared(eventAppeared), OnLiveProcessingStarted(liveProcessingStarted), OnSubscriptionDropped(subscriptionDropped)); }
static void FromAll(IEventStoreConnection con, UserCredentials userCredentials) { var sub = con.SubscribeToAllFrom(Position.Start, true, Appeared, Live, Dropped, userCredentials); // sub.Start(); var read = con.ReadAllEventsForward(Position.Start, 1000, true, userCredentials); var mre = new ManualResetEvent(false); mre.WaitOne(3000); var rgpsa = events.GroupBy(g => g.Event.EventId).ToList(); int i = 0; var rgps = events.Select(s => new { s, position = i++ }).GroupBy(g => g.s.Event.EventId).ToList(); var rgps2 = read.Events.Select(s => new { s, position = i++ }).GroupBy(g => g.s.Event.EventId).ToList(); foreach (var r in rgps) { var values = r.ToArray(); } Console.ReadLine(); }