Skip to content

Commit

Permalink
read stream ce
Browse files Browse the repository at this point in the history
  • Loading branch information
RossBugginsNHS committed Dec 22, 2023
1 parent cbe8668 commit c7a3b6f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions esdb/app/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -28,7 +31,7 @@
);

await client.AppendToStreamAsync(
streamName,
streamPrefix + userNumber,
StreamState.Any,
new[] { eventData },
cancellationToken: cancellationToken
Expand All @@ -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<TestEvent>(e.Event.Data.ToArray());
Console.WriteLine(e.Event.EventNumber + "\t" + e.Event.EventType + "\t" + te);
await Task.Yield();
});
}, resolveLinkTos: true);

await t;

Expand Down

0 comments on commit c7a3b6f

Please sign in to comment.