-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
43 lines (35 loc) · 1.62 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using EventStore.Client;
namespace ClientApp
{
internal class Program
{
private static async Task Main(string[] args)
{
var client = Client.CreateClient();
var streamName = "a-good-stream-name-nonexixting";
// Setup a subscription starting from the current end of the stream.
var sub = await client.SubscribeToStreamAsync(streamName, StreamPosition.End, EventAppeared);
// hacky way of getting last revision, do not use!
var revision = await client.GetLastRevisionOnStream(streamName);
var writeResult = await client.AppendToStreamAsync(streamName, revision, SampleData.GetSampleData());
// Next revision number to be used
revision = writeResult.NextExpectedStreamRevision;
// A read that will fetch the 5 last items.
await using var readStreamResult =
client.ReadStreamAsync(Direction.Backwards, streamName, StreamPosition.End, 5);
if (await readStreamResult.ReadState == ReadState.Ok)
await foreach (var res in readStreamResult)
Console.WriteLine($"Reading event number: {res.OriginalEventNumber}");
}
private static Task EventAppeared(StreamSubscription subscription, ResolvedEvent resolvedEvent,
CancellationToken token)
{
Console.WriteLine($"Subscription event number: {resolvedEvent.OriginalEventNumber}");
return Task.CompletedTask;
}
}
}