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 repartitionByUser_Click(object sender, EventArgs e) { //pm.Enable("$users", userCredentials); pm.CreateContinuous("partition-by-user", @" fromCategory('activities') .when({ ActivityCompleted: function(s, e) { linkTo('everything-' + e.data.user, e); var i; for(i = 0; i < e.data.mentions.length; ++i){ linkTo('everything-' + e.data.mentions[i], e); } return s; }, }) ", userCredentials); if (eventStoreProjectionSubscription == null) { eventStoreProjectionSubscription = connection.SubscribeToStream("everything-" + readAs.Text, true, (x, y) => AppendToEverythingReadLog(x, y)); } }
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 Task EventAppeared(EventStoreSubscription eventStorePersistentSubscriptionBase, ResolvedEvent resolvedEvent) { var @event = resolvedEvent.Event; if (@event == null || [email protected]) { return(Task.FromResult(0)); } var eventName = resolvedEvent.Event.EventStreamId; var jsonBytes = resolvedEvent.Event.Data; var eventId = resolvedEvent.Event.EventId; var events = _subscriptionConfiguration.SubscribedEvents; if (events.All(q => q.Key != eventName)) { return(Task.FromResult(0)); } var eventContext = new EventStoreContext(eventId, eventName, resolvedEvent, string.Empty, events, _container); _projectorInvoker.Invoke(eventContext); return(Task.FromResult(0)); }
private Task GotDebit(EventStoreSubscription sub, ResolvedEvent resolvedEvent) { _debitCount++; _view.Debits = _debitCount; _view.Transactions = _creditCount + _debitCount; return(Task.CompletedTask); }
public Task Process(EventStoreSubscription sub, ResolvedEvent e) { _logger.LogInformation($"StreamId={sub.StreamId},SubscriptionName={sub.StreamId}"); var x = $"Data={UTF8Encoding.UTF8.GetString(e.Event.Data)},Type={e.Event.EventType},StreamId={e.OriginalStreamId}"; _logger.LogInformation(x); return(Task.CompletedTask); }
private void startReading_Click(object sender, EventArgs e) { if (eventStoreSubscription == null) { eventStoreSubscription = connection.SubscribeToStream("activities-" + readAs.Text, true, (x, y) => AppendToReadLog(x, y)); } }
private void SubscriptionDropped(EventStoreSubscription eventStoreSubscription, SubscriptionDropReason subscriptionDropReason, Exception arg3) { if (this._stop) { return; } this.RecoverSubscription(); }
private void PrintEvent(EventStoreSubscription eventStoreSubscription, ResolvedEvent resolvedEvent) { _testOutputHelper.WriteLine($"Event {_eventCounter++}"); _testOutputHelper.WriteLine($" {eventStoreSubscription.StreamId}"); _testOutputHelper.WriteLine($" {resolvedEvent.Event.EventType}"); _testOutputHelper.WriteLine($" {resolvedEvent.Event.EventStreamId}"); _testOutputHelper.WriteLine($" {resolvedEvent.Event.IsJson}"); _testOutputHelper.WriteLine($" {Encoding.UTF8.GetString(resolvedEvent.Event.Data)}"); }
private void SubscriptionDropped(EventStoreSubscription subscription, SubscriptionDropReason dropReason, Exception exception) { if (stop) { return; } RecoverSubscription().GetAwaiter().GetResult(); }
async Task SubscribeToClient() { var task = _context.Connection.SubscribeToStreamAsync( TimelineStreams.Client, resolveLinkTos: false, eventAppeared: (_, e) => OnNextFromClient(e), subscriptionDropped: (_, reason, error) => OnDropped(reason, error)); _clientSubscription = await task.ConfigureAwait(false); }
private static Task EventAppeared(EventStoreSubscription arg1, ResolvedEvent arg2) { var type = Type.GetType(arg2.Event.EventType); if (type != null && typeof(DomainEvent).IsAssignableFrom(type)) { Console.WriteLine(Encoding.UTF8.GetString(arg2.Event.Data)); } return(Task.CompletedTask); }
public void ConfirmSubscription(long lastCommitPosition, int? lastEventNumber) { if (lastCommitPosition < -1) throw new ArgumentOutOfRangeException("lastCommitPosition", string.Format("Invalid lastCommitPosition {0} on subscription confirmation.", lastCommitPosition)); if (_subscription != null) throw new Exception("Double confirmation of subscription."); _subscription = new EventStoreSubscription(Unsubscribe, _streamId, lastCommitPosition, lastEventNumber); _source.SetResult(_subscription); }
private void CommandResponseReceived(EventStoreSubscription subscription, ResolvedEvent resolvedEvent) { if (ResponseReceived == null) { return; } var response = resolvedEvent.ParseJson <CommandResponse>(); ResponseReceived(this, new CommandResponseEventArgs(response)); }
private void DisplayNotificationArrival(EventStoreSubscription subscription, ResolvedEvent notification) { RecordedEvent @event = notification.Event; string eventTypePrefix = @event.Data.GetType().AssemblyQualifiedName; if (string.IsNullOrWhiteSpace(@event.EventType) || @event.EventType != eventTypePrefix) { return; } Console.WriteLine("{0} : {1}", eventTypePrefix, @event.EventType); }
private void SubscriptionDropped(EventStoreSubscription subscription, SubscriptionDropReason dropReason, Exception e) { if (e != null) { _observer.OnError(e); } else { _observer.OnCompleted(); } }
private async void ConnectToSubscription() { try { _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User); } catch { _conn.ConnectAsync().Wait(); _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User); } }
static void ProcessEvent( EventStoreSubscription subscription, ResolvedEvent resolvedEvent) { var evt = resolvedEvent.Event; Console.WriteLine(evt.EventStreamId); Console.WriteLine(evt.EventType); var jsonData = Encoding.UTF8.GetString(evt.Data); Console.WriteLine(jsonData); }
public async Task RegisterAsync(Type eventType) { if (_subscribedEventTypes.Contains(eventType)) { return; } if (_subscription == null) { //TODO: lock etc? _subscription = await _connection.SubscribeToAllAsync(true, OnEventDelivered, OnSubscriptionDropped, new UserCredentials("admin", "changeit")); } _subscribedEventTypes.Add(eventType); }
internal async Task EnsureSubscribed() { if (_subscription == null && AcquireSubscribeLock()) { try { _subscription = await SubscribeToStream(); } finally { ReleaseSubscribeLock(); } } }
private static Task EventAppeared(EventStoreSubscription eventStorePersistentSubscriptionBase, ResolvedEvent resolvedEvent) { var data = Encoding.ASCII.GetString(resolvedEvent.Event.Data); if (resolvedEvent.Event.EventType[0] != '$') { return(EventStoreConnection.publishToReadModel(resolvedEvent)); } else { return(Task.FromResult(0)); } }
private static void OnEventRecieved(EventStoreSubscription es, ResolvedEvent e) { var json = Encoding.UTF8.GetString(e.Event.Data); var message = JsonConvert.DeserializeObject <ChatMessage>(json); if (message == null) { Console.WriteLine(e.Event.EventStreamId + "/Undefined"); } else { Console.WriteLine(e.Event.EventStreamId + "/" + message.User + ":" + message.Message); } }
public void ConfirmSubscription(long lastCommitPosition, int?lastEventNumber) { if (lastCommitPosition < -1) { throw new ArgumentOutOfRangeException("lastCommitPosition", string.Format("Invalid lastCommitPosition {0} on subscription confirmation.", lastCommitPosition)); } if (_subscription != null) { throw new Exception("Double confirmation of subscription."); } _subscription = new EventStoreSubscription(Unsubscribe, _streamId, lastCommitPosition, lastEventNumber); _source.SetResult(_subscription); }
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 AppendToEverythingReadLog(EventStoreSubscription eventStoreSubscription, ResolvedEvent resolvedEvent) { while (everythingWindow.Count > 20) { everythingWindow.Dequeue(); } var j = JObject.Parse(Encoding.UTF8.GetString(resolvedEvent.Event.Data)); everythingWindow.Enqueue(string.Format("Activity: {0}:{1}:{2} Mentionned by {3}", j.Value <string>("user"), j.Value <string>("type"), j.Value <string>("decription"), j.Value <JArray>("mentions").Select(x => x.ToString()).Aggregate((x, y) => x + " " + y))); var text = everythingWindow.Aggregate((x, y) => x + "\r\n" + y); BeginInvoke(new Action(() => everythingEvents.Text = text)); }
public Task<EventStoreSubscription> Subscribe(string streamId, bool resolveLinkTos, Action<ResolvedEvent> eventAppeared, Action subscriptionDropped) { var id = Guid.NewGuid(); var eventStoreSubscription = new EventStoreSubscription(id, streamId, this, eventAppeared, subscriptionDropped); var subscriptionTaskPair = new SubscriptionTaskPair(eventStoreSubscription); if (!_subscriptions.TryAdd(id, subscriptionTaskPair)) throw new Exception("Failed to add subscription. Concurrency failure."); var subscribe = new ClientMessage.SubscribeToStream(streamId, resolveLinkTos); var pkg = new TcpPackage(TcpCommand.SubscribeToStream, id, subscribe.Serialize()); _connection.EnqueueSend(pkg.AsByteArray()); return subscriptionTaskPair.TaskCompletionSource.Task; }
private async void ConnectToSubscription() { var bufferSize = 10; var autoAck = true; try { _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User); } catch { _conn.ConnectAsync().Wait(); _subscription = await _conn.SubscribeToAllAsync(false, EventAppeared, SubscriptionDropped, User); } }
private void EventAppeared(EventStoreSubscription subscription, ResolvedEvent evt) { try { dynamic message = evt.DeserializeEvent(); if (message is Message) { _bus.Handle(message); } } catch { //ignore } }
private static Task EventAppeared(EventStoreSubscription arg1, ResolvedEvent arg2) { var type = Type.GetType(arg2.Event.EventType); if (type != null && typeof(DomainEvent).IsAssignableFrom(type)) { var json = Encoding.UTF8.GetString(arg2.Event.Data); var @event = JsonConvert.DeserializeObject(json, type); bus.Publish(@event).Wait(); Console.WriteLine("Dispatched on bus.."); Console.WriteLine("=================================================="); } return(Task.CompletedTask); }
private void EventAppeared(EventStoreSubscription subscription, ResolvedEvent resolvedEvent) { try { var @event = EventDeserializer.Deserialize <T>(resolvedEvent); if (@event != null) { _observer.OnNext(@event); } } catch (Exception e) { _observer.OnError(e); } }
private async Task OnEventDelivered(EventStoreSubscription subscription, ResolvedEvent resolvedEvent) { if (!_typeResolver.TryGetType(resolvedEvent.Event.EventType, out var eventType)) { return; } if (!_subscribedEventTypes.Contains(eventType)) { return; } var @event = _deserializer.Deserialize(resolvedEvent, eventType); foreach (var eventProcessor in _eventProcessors) { await eventProcessor.ProcessAsync(@event); } }
private void RecoverSubscription() { this._livePublishingAllowed = false; this._liveDone.Wait(); // wait until all live processing is finished (queue is empty, _lastProcessed updated) this._allowProcessing = true; //AN: if _lastProcessed == (-1, -1) then we haven't processed anything yet, so we start from Position.Start var startPos = this._lastProcessed == new Position(-1, -1) ? Position.Start : this._lastProcessed; var nextPos = this.ReadHistoricalEventsFrom(startPos); this._eventStoreSubscription = this.SubscribeToAll(); this.ReadHistoricalEventsFrom(nextPos); this._historicalDone.Wait(); // wait until historical queue is empty and _lastProcessed updated this._livePublishingAllowed = true; this.EnsurePublishEvents(this._liveQueue, this._liveDone); }
public SubscriptionTaskPair(EventStoreSubscription subscription) { Ensure.NotNull(subscription, "subscription"); Subscription = subscription; TaskCompletionSource = new TaskCompletionSource<EventStoreSubscription>(); }
private void ConfirmSubscription(long lastCommitPosition, int? lastEventNumber) { if (lastCommitPosition < -1) throw new ArgumentOutOfRangeException("lastCommitPosition", string.Format("Invalid lastCommitPosition {0} on subscription confirmation.", lastCommitPosition)); if (_subscription != null) throw new Exception("Double confirmation of subscription."); if (_verboseLogging) _log.Debug("Subscription {0:B} to {1}: subscribed at CommitPosition: {2}, EventNumber: {3}.", _correlationId, _streamId == string.Empty ? "<all>" : _streamId, lastCommitPosition, lastEventNumber); _subscription = new EventStoreSubscription(this, _streamId, lastCommitPosition, lastEventNumber); _source.SetResult(_subscription); }