From c7a3b6f0c2a1a3994895ef3a04b1f8d4163ad1af Mon Sep 17 00:00:00 2001 From: "ross.buggins" <78215796+RossBugginsNHS@users.noreply.github.com> Date: Fri, 22 Dec 2023 13:27:29 +0000 Subject: [PATCH] read stream ce --- esdb/app/src/Program.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/esdb/app/src/Program.cs b/esdb/app/src/Program.cs index b5034df..43cea56 100644 --- a/esdb/app/src/Program.cs +++ b/esdb/app/src/Program.cs @@ -7,8 +7,9 @@ const string connectionString = "esdb://admin:changeit@node1:2113?tls=false&tlsVerifyCert=false"; -const string streamName = "some-stream"; +const string streamPrefix = "users-"; const string eventType = "TestEvent"; +const string streamsReadPrefix = "$ce-users"; var settings = EventStoreClientSettings.Create(connectionString); var client = new EventStoreClient(settings); @@ -19,6 +20,8 @@ { while (!cancellationToken.IsCancellationRequested) { + var userNumber = 123; + Console.WriteLine("Writing event"); var evt = new TestEvent(Guid.NewGuid().ToString("N"), "I wrote my first event!"); var eventData = new EventData( @@ -28,7 +31,7 @@ ); await client.AppendToStreamAsync( - streamName, + streamPrefix + userNumber, StreamState.Any, new[] { eventData }, cancellationToken: cancellationToken @@ -39,20 +42,14 @@ await client.AppendToStreamAsync( } }); -var result = client.ReadStreamAsync( - Direction.Forwards, - streamName, - StreamPosition.Start, - cancellationToken: cancellationToken -); -await client.SubscribeToStreamAsync(streamName, FromStream.Start, async (s, e, c) => +await client.SubscribeToStreamAsync(streamsReadPrefix, FromStream.Start, async (s, e, c) => { var te = JsonSerializer.Deserialize(e.Event.Data.ToArray()); Console.WriteLine(e.Event.EventNumber + "\t" + e.Event.EventType + "\t" + te); await Task.Yield(); -}); +}, resolveLinkTos: true); await t;