private static async Task EventTypePrefix(EventStoreClient client) { #region event-type-prefix var filter = new SubscriptionFilterOptions( EventTypeFilter.Prefix("customer-")); #endregion event-type-prefix await client.SubscribeToAllAsync(Position.Start, (s, e, c) => { Console.WriteLine( $"{e.Event.EventType} @ {e.Event.Position.PreparePosition}"); return(Task.CompletedTask); }, filterOptions : filter ); }
public async Task SubscribeToStreams(IStreamPosition streamPosition, params SubscriptionInfo[] eventTypes) { var methods = new Dictionary <string, Func <IStreamSubscription, ResolvedEvent, CancellationToken, Task> >(); var prefixes = eventTypes.Select(x => x.EventType.Name).ToArray(); var filter = EventTypeFilter.Prefix(prefixes); FilterOptions filterOptions = new FilterOptions(filter); var esStreamPosition = ((StreamPosition)(streamPosition)).GlobalPosition; var handlers = eventTypes.ToDictionary(x => x.EventType.Name, x => x.HandlerType); var dict = eventTypes.Select(x => x.EventType).ToDictionary(x => x.Name); await _connection.SubscribeToAllAsync(esStreamPosition, async (s, r, c) => { await OnEventAppearead(s, r, methods, handlers, dict, c); }, true, OnDropped, filterOptions); }
static async Task Main() { using var client = new EventStoreClient( EventStoreClientSettings.Create("esdb://*****:*****@ {e.Event.Position.PreparePosition}"); return(Task.CompletedTask); }, filterOptions : new SubscriptionFilterOptions( EventTypeFilter.Prefix("some-"), 1, (s, p, c) => { Console.WriteLine($"checkpoint taken at {p.PreparePosition}"); return(Task.CompletedTask); }) ); Thread.Sleep(2000); for (var i = 0; i < 100; i++) { var eventData = new EventData( Uuid.NewUuid(), i % 2 == 0 ? "some-event" : "other-event", Encoding.UTF8.GetBytes("{\"id\": \"1\" \"value\": \"some value\"}") ); await client.AppendToStreamAsync( Guid.NewGuid().ToString("N"), StreamRevision.None, new List <EventData> { eventData } ); } Console.ReadLine(); }