private Task EnqueuePushedEvent(EventStoreSubscription subscription, ResolvedEvent e) { if (Verbose) { Log.Debug("Catch-up Subscription {0} to {1}: event appeared ({2}, {3}, {4} @ {5}).", SubscriptionName, IsSubscribedToAll ? "<all>" : StreamId, e.OriginalStreamId, e.OriginalEventNumber, e.OriginalEvent.EventType, e.OriginalPosition); } if (_liveQueue.Count >= MaxPushQueueSize) { EnqueueSubscriptionDropNotification(SubscriptionDropReason.ProcessingQueueOverflow, null); subscription.Unsubscribe(); return(Task.CompletedTask); } _liveQueue.Enqueue(e); if (_allowProcessing) { EnsureProcessingPushQueue(); } return(Task.CompletedTask); }
private void Dropped(EventStoreSubscription subscription, SubscriptionDropReason subscriptionDropReason, Exception exception) { var message = string.Format("Subscription {0} dropped: {1} (Recovery currently not implemented){2}{3}", subscription.StreamId, subscriptionDropReason, Environment.NewLine, exception); _console.Error(message); }
private void SubscribeToStream() { if (!ShouldStop) { if (Verbose) { Log.Debug("Catch-up Subscription to {0}: subscribing...", IsSubscribedToAll ? "<all>" : StreamId); } var subscribeTask = _streamId == string.Empty ? _connection.SubscribeToAllAsync(_resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials) : _connection.SubscribeToStreamAsync(_streamId, _resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials); subscribeTask.ContinueWith(_ => HandleErrorOrContinue(_, () => { _subscription = _.Result; ReadMissedHistoricEvents(); }), TaskContinuationOptions.AttachedToParent); } else { DropSubscription(SubscriptionDropReason.UserInitiated, null); } }
private async Task SubscribeToStreamAsync() { if (!ShouldStop) { if (Verbose) { Log.Debug("Catch-up Subscription {0} to {1}: subscribing...", SubscriptionName, IsSubscribedToAll ? "<all>" : StreamId); } var subscription = StreamId == string.Empty ? await _connection.SubscribeToAllAsync(_resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials).ConfigureAwait(false) : await _connection.SubscribeToStreamAsync(StreamId, _resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials).ConfigureAwait(false); _subscription = subscription; await ReadMissedHistoricEventsAsync().ConfigureAwait(false); } else { DropSubscription(SubscriptionDropReason.UserInitiated, null); } }
private void CommandResponseReceived(EventStoreSubscription subscription, ResolvedEvent resolvedEvent) { if (ResponseReceived == null) return; var response = resolvedEvent.ParseJson<CommandResponse>(); ResponseReceived(this, new CommandResponseEventArgs(response)); }
public void Start() { ThreadPool.QueueUserWorkItem(_ => { if (Verbose) { Log.Debug("Catch-up Subscription to {0}: starting...", IsSubscribedToAll ? "<all>" : StreamId); } _stopped.Reset(); try { if (Verbose) { Log.Debug("Catch-up Subscription to {0}: pulling events...", IsSubscribedToAll ? "<all>" : StreamId); } ReadEventsTill(_connection, _resolveLinkTos, _userCredentials, null, null); if (!_stop) { if (Verbose) { Log.Debug("Catch-up Subscription to {0}: subscribing...", IsSubscribedToAll ? "<all>" : StreamId); } _subscription = _streamId == string.Empty ? _connection.SubscribeToAll(_resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials) : _connection.SubscribeToStream(_streamId, _resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials); if (Verbose) { Log.Debug("Catch-up Subscription to {0}: pulling events (if left)...", IsSubscribedToAll ? "<all>" : StreamId); } ReadEventsTill(_connection, _resolveLinkTos, _userCredentials, _subscription.LastCommitPosition, _subscription.LastEventNumber); } } catch (Exception exc) { DropSubscription(SubscriptionDropReason.CatchUpError, exc); return; } if (_stop) { DropSubscription(SubscriptionDropReason.UserInitiated, null); return; } if (Verbose) { Log.Debug("Catch-up Subscription to {0}: processing live events...", IsSubscribedToAll ? "<all>" : StreamId); } if (_liveProcessingStarted != null) { _liveProcessingStarted(this); } _allowProcessing = true; EnsureProcessingPushQueue(); }); }
private void EventAppeard(EventStoreSubscription subscription, ResolvedEvent @event) { var representation = _deserializer.GetRepresentation(_serializer, @event.OriginalEvent); var payload = representation.Payload; if (payload != null) { _self.Tell(payload); } }
private void SubscriptionDropped(ESSubscription subscription, SubscriptionDropReason subscriptionDropReason, Exception ex) { if (_cancellationRequestedByUser) { _logger.LogInformation(ex, $"Subscription stopped by user: {subscriptionDropReason.ToString()}"); return; } _logger.LogError(ex, $"Subscription dropped: {subscriptionDropReason.ToString()}"); _connection.Dispose(); Connect().Wait(); }
private void EventAppeared(EventStoreSubscription sub, ResolvedEvent e) { Log.Debug(_adapterName + " received " + Encoding.UTF8.GetString(e.Event.Data)); var request = Json.From<SearchRequested>(Encoding.UTF8.GetString(e.Event.Data)); try { var response = _endpoint.GetQuoteFor(request); Publish(request.ClientResponseStream, response); } catch (Exception ex) { Log.Exception(_adapterName + " endpoint caused exception", ex); } }
private void Appeared(EventStoreSubscription subscription, ResolvedEvent data) { var recordedEvent = data.Event; if (IsSystemStream(recordedEvent.EventStreamId)) return; var linkedStream = data.Link != null ? data.Link.EventStreamId : null; if (IsSystemStream(linkedStream)) return; var eventDefinition = _knownEventsProvider.Get(recordedEvent); _console.Log( eventDefinition.Color, "{0}: {1} ({2})", recordedEvent.EventType, eventDefinition.Parse(), FormatStream(linkedStream, recordedEvent)); }
private void EventAppeared(EventStoreSubscription eventStoreSubscription, ResolvedEvent arg2) { if (arg2.Event.EventType.StartsWith("$")) { return; } var evnt = DeserializeEvent(arg2.OriginalEvent.Metadata, arg2.OriginalEvent.Data); if (evnt == null) { return; } evnt.AggregateId = arg2.OriginalEvent.EventId; evnt.Version = arg2.OriginalEvent.EventNumber; _eventPublisher.Publish(evnt); }
private async Task Connect() { _connection = _connectionProvider.GetConnection(); await _connection.ConnectAsync(); Func <EventStoreCatchUpSubscription, ResolvedEvent, Task> processEvent = (subscriptionBase, resolvedEvent) => { return(HandleEvent(resolvedEvent)); }; Func <ESSubscription, ResolvedEvent, Task> processEventAlt = (subscriptionBase, resolvedEvent) => { return(HandleEvent(resolvedEvent)); }; var streamId = _streamId == null ? $"$ce-{_aggregateType.ToUpper()}" : _streamId.Id; if (_startPosition == StreamPosition.End) { _subscriptionBase = await _connection.SubscribeToStreamAsync( streamId, true, processEventAlt, subscriptionDropped : SubscriptionDropped); _connected = true; _status = SubscriptionConnectionStatus.Connected; } else { _catchUpSubscriptionBase = _connection.SubscribeToStreamFrom( streamId, 0, new CatchUpSubscriptionSettings( CatchUpSubscriptionSettings.Default.MaxLiveQueueSize, CatchUpSubscriptionSettings.Default.ReadBatchSize, false, true, CatchUpSubscriptionSettings.Default.SubscriptionName), processEvent, subscriptionDropped: SubscriptionDropped); _connected = true; _status = SubscriptionConnectionStatus.Connected; } }
public void StartListening() { // // This can also be done with competing consumers for load balancing // the workload across many of the same adapter. In order to use // competing consumers you would use ConnectToPersistentSubscription // and first create a named persistent subscription to connect to // // *note that the code from competing branch is not yet merged to master // // Also note that this is currently using an admin user for subscribing // in most systems a specific user would be prefered as opposed to using // an admin user for this behaviour. _subscription = _connection.SubscribeToStreamAsync(_incomingStream, false, EventAppeared, SubscriptionDropped, _credentials).Result; }
private Task EnqueueCheckpointReached(EventStoreSubscription subscription, Position position) { if (Verbose) { Log.Debug("Catch-up Subscription {0} to <all>: checkpoint reached @ {1}.", position); } if (LiveQueue.Count >= MaxPushQueueSize) { EnqueueSubscriptionDropNotification(SubscriptionDropReason.ProcessingQueueOverflow, null); subscription.Unsubscribe(); return(TaskEx.CompletedTask); } EnqueueAction(() => CheckpointReachedAction(position)); if (AllowProcessing) { EnsureProcessingPushQueue(); } return(TaskEx.CompletedTask); }
private Task OnEventAppeared(EventStoreSubscription subscription, ResolvedEvent resolvedEvent) { Enqueue(resolvedEvent); return(Task.CompletedTask); }
private void TodoChangedSubscriptionDropped(EventStoreSubscription sub, SubscriptionDropReason reason, Exception ex) { SubscribeToStreamTodo(); }
private void TodoChanged(EventStoreSubscription sub, ResolvedEvent evt) { ServerEventsHub.CallClientTodosUpdated(); }
private void CommentChangedSubscriptionDropped(EventStoreSubscription sub, SubscriptionDropReason reason, Exception ex) { SubscribeToStreamComment(); }
private void SubscriptionDropped(EventStoreSubscription subscription, SubscriptionDropReason reason, Exception exception) { _log.Error(exception, "Subscription dropped. Reason: {0}", reason); SubscribeToStream(); }
private void SubscribeToStream() { if (!ShouldStop) { if (Verbose) Log.Debug("Catch-up Subscription to {0}: subscribing...", IsSubscribedToAll ? "<all>" : StreamId); var subscribeTask = _streamId == string.Empty ? _connection.SubscribeToAllAsync(_resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials) : _connection.SubscribeToStreamAsync(_streamId, _resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials); subscribeTask.ContinueWith(_ => HandleErrorOrContinue(_, () => { _subscription = _.Result; ReadMissedHistoricEvents(); }), TaskContinuationOptions.AttachedToParent); } else { DropSubscription(SubscriptionDropReason.UserInitiated, null); } }
private void OnEventAppeared(EventStoreSubscription subscription, ResolvedEvent resolvedEvent) { Enqueue(resolvedEvent); }
private void SubscriptionDropped(EventStoreSubscription eventStoreSubscription, SubscriptionDropReason subscriptionDropReason, Exception arg3) { //throw new NotImplementedException(); }
private void ServerSubscriptionDropped(EventStoreSubscription subscription, SubscriptionDropReason reason, Exception exc) { EnqueueSubscriptionDropNotification(reason, exc); }
private void Dropped(EventStoreSubscription subscription, SubscriptionDropReason subscriptionDropReason, Exception exception) { _console.Error("Subscription {0} dropped: {1} (Currently no recovery implemented){2}{3}", subscription.StreamId, subscriptionDropReason, Environment.NewLine, exception); }
private void GotDebit(EventStoreSubscription sub, ResolvedEvent resolvedEvent) { _debitCount ++; _view.Debits = _debitCount; _view.Transactions = _creditCount + _debitCount; }
public void Start() { ThreadPool.QueueUserWorkItem(_ => { if (Verbose) Log.Debug("Catch-up Subscription to {0}: starting...", IsSubscribedToAll ? "<all>" : StreamId); _stopped.Reset(); try { if (Verbose) Log.Debug("Catch-up Subscription to {0}: pulling events...", IsSubscribedToAll ? "<all>" : StreamId); ReadEventsTill(_connection, _resolveLinkTos, _userCredentials, null, null); if (!_stop) { if (Verbose) Log.Debug("Catch-up Subscription to {0}: subscribing...", IsSubscribedToAll ? "<all>" : StreamId); _subscription = _streamId == string.Empty ? _connection.SubscribeToAll(_resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials) : _connection.SubscribeToStream(_streamId, _resolveLinkTos, EnqueuePushedEvent, ServerSubscriptionDropped, _userCredentials); if (Verbose) Log.Debug("Catch-up Subscription to {0}: pulling events (if left)...", IsSubscribedToAll ? "<all>" : StreamId); ReadEventsTill(_connection, _resolveLinkTos, _userCredentials, _subscription.LastCommitPosition, _subscription.LastEventNumber); } } catch (Exception exc) { DropSubscription(SubscriptionDropReason.CatchUpError, exc); return; } if (_stop) { DropSubscription(SubscriptionDropReason.UserInitiated, null); return; } if (Verbose) Log.Debug("Catch-up Subscription to {0}: processing live events...", IsSubscribedToAll ? "<all>" : StreamId); if (_liveProcessingStarted != null) _liveProcessingStarted(this); _allowProcessing = true; EnsureProcessingPushQueue(); }); }
private void SubscriptionDropped(EventStoreSubscription sub, SubscriptionDropReason reason, Exception exception) { Log.Debug(_adapterName + " lost subscription due to " + reason); }
private void EnqueuePushedEvent(EventStoreSubscription subscription, ResolvedEvent e) { if (Verbose) Log.Debug("Catch-up Subscription to {0}: event appeared ({1}, {2}, {3} @ {4}).", IsSubscribedToAll ? "<all>" : StreamId, e.OriginalStreamId, e.OriginalEventNumber, e.OriginalEvent.EventType, e.OriginalPosition); if (_liveQueue.Count >= MaxPushQueueSize) { EnqueueSubscriptionDropNotification(SubscriptionDropReason.ProcessingQueueOverflow, null); subscription.Unsubscribe(); return; } _liveQueue.Enqueue(e); if (_allowProcessing) EnsureProcessingPushQueue(); }
private void ValueChanged(EventStoreSubscription eventStoreSubscription, ResolvedEvent resolvedEvent, Action<MeasurementReadCounter> valueChanged) { var value = resolvedEvent.ParseJson<MeasurementReadCounter>(); valueChanged(value); }
private void SubscriptionDropped(EventStoreSubscription arg1, SubscriptionDropReason arg2, Exception arg3) { Subsribe(); }