1
- using KurrentDB . Client ;
2
-
3
- #pragma warning disable CS8321 // Local function is declared but never used
1
+ #pragma warning disable CS8321 // Local function is declared but never used
4
2
5
3
// ReSharper disable UnusedParameter.Local
6
4
// ReSharper disable UnusedVariable
7
5
8
6
await using var client = new KurrentDBClient ( KurrentDBClientSettings . Create ( "esdb://localhost:2113?tls=false" ) ) ;
9
7
10
- await Task . WhenAll ( YieldSamples ( ) . Select ( async sample => {
11
- try {
12
- await sample ;
13
- } catch ( OperationCanceledException ) { }
14
- } ) ) ;
15
-
8
+ await Task . WhenAll (
9
+ YieldSamples ( ) . Select (
10
+ async sample => {
11
+ try {
12
+ await sample ;
13
+ } catch ( OperationCanceledException ) { }
14
+ }
15
+ )
16
+ ) ;
16
17
17
18
return ;
18
19
@@ -34,8 +35,12 @@ static async Task SubscribeToStreamFromPosition(KurrentDBClient client, Cancella
34
35
35
36
await using var subscription = client . SubscribeToStream (
36
37
"some-stream" ,
37
- FromStream . After ( StreamPosition . FromInt64 ( 20 ) ) ,
38
- cancellationToken : ct ) ;
38
+ new SubscribeToStreamOptions {
39
+ Start = FromStream . After ( StreamPosition . FromInt64 ( 20 ) )
40
+ } ,
41
+ cancellationToken : ct
42
+ ) ;
43
+
39
44
await foreach ( var message in subscription . Messages ) {
40
45
switch ( message ) {
41
46
case StreamMessage . Event ( var evnt ) :
@@ -53,8 +58,10 @@ static async Task SubscribeToStreamLive(KurrentDBClient client, CancellationToke
53
58
54
59
await using var subscription = client . SubscribeToStream (
55
60
"some-stream" ,
56
- FromStream . End ,
57
- cancellationToken : ct ) ;
61
+ new SubscribeToStreamOptions { Start = FromStream . End } ,
62
+ cancellationToken : ct
63
+ ) ;
64
+
58
65
await foreach ( var message in subscription . Messages ) {
59
66
switch ( message ) {
60
67
case StreamMessage . Event ( var evnt ) :
@@ -72,9 +79,10 @@ static async Task SubscribeToStreamResolvingLinkTos(KurrentDBClient client, Canc
72
79
73
80
await using var subscription = client . SubscribeToStream (
74
81
"$et-myEventType" ,
75
- FromStream . Start ,
76
- true ,
77
- cancellationToken : ct ) ;
82
+ new SubscribeToStreamOptions { ResolveLinkTos = true } ,
83
+ cancellationToken : ct
84
+ ) ;
85
+
78
86
await foreach ( var message in subscription . Messages ) {
79
87
switch ( message ) {
80
88
case StreamMessage . Event ( var evnt ) :
@@ -91,16 +99,18 @@ static async Task SubscribeToStreamSubscriptionDropped(KurrentDBClient client, C
91
99
#region subscribe-to-stream-subscription-dropped
92
100
93
101
var checkpoint = await ReadStreamCheckpointAsync ( ) switch {
94
- null => FromStream . Start ,
102
+ null => FromStream . Start ,
95
103
var position => FromStream . After ( position . Value )
96
104
} ;
97
105
98
106
Subscribe :
99
107
try {
100
108
await using var subscription = client . SubscribeToStream (
101
109
"some-stream" ,
102
- checkpoint ,
103
- cancellationToken : ct ) ;
110
+ new SubscribeToStreamOptions { Start = checkpoint } ,
111
+ cancellationToken : ct
112
+ ) ;
113
+
104
114
await foreach ( var message in subscription . Messages ) {
105
115
switch ( message ) {
106
116
case StreamMessage . Event ( var evnt ) :
@@ -125,10 +135,8 @@ static async Task SubscribeToStreamSubscriptionDropped(KurrentDBClient client, C
125
135
static async Task SubscribeToStream ( KurrentDBClient client , CancellationToken ct ) {
126
136
#region subscribe-to-stream
127
137
128
- await using var subscription = client . SubscribeToStream (
129
- "some-stream" ,
130
- FromStream . Start ,
131
- cancellationToken : ct ) ;
138
+ await using var subscription = client . SubscribeToStream ( "some-stream" , cancellationToken : ct ) ;
139
+
132
140
await foreach ( var message in subscription . Messages . WithCancellation ( ct ) ) {
133
141
switch ( message ) {
134
142
case StreamMessage . Event ( var evnt ) :
@@ -144,9 +152,8 @@ static async Task SubscribeToStream(KurrentDBClient client, CancellationToken ct
144
152
static async Task SubscribeToAll ( KurrentDBClient client , CancellationToken ct ) {
145
153
#region subscribe-to-all
146
154
147
- await using var subscription = client . SubscribeToAll (
148
- FromAll . Start ,
149
- cancellationToken : ct ) ;
155
+ await using var subscription = client . SubscribeToAll ( cancellationToken : ct ) ;
156
+
150
157
await foreach ( var message in subscription . Messages ) {
151
158
switch ( message ) {
152
159
case StreamMessage . Event ( var evnt ) :
@@ -169,8 +176,12 @@ static async Task SubscribeToAllFromPosition(KurrentDBClient client, Cancellatio
169
176
) ;
170
177
171
178
await using var subscription = client . SubscribeToAll (
172
- FromAll . After ( result . LogPosition ) ,
173
- cancellationToken : ct ) ;
179
+ new SubscribeToAllOptions {
180
+ Start = FromAll . After ( result . LogPosition )
181
+ } ,
182
+ cancellationToken : ct
183
+ ) ;
184
+
174
185
await foreach ( var message in subscription . Messages ) {
175
186
switch ( message ) {
176
187
case StreamMessage . Event ( var evnt ) :
@@ -187,8 +198,12 @@ static async Task SubscribeToAllLive(KurrentDBClient client, CancellationToken c
187
198
#region subscribe-to-all-live
188
199
189
200
var subscription = client . SubscribeToAll (
190
- FromAll . End ,
191
- cancellationToken : ct ) ;
201
+ new SubscribeToAllOptions {
202
+ Start = FromAll . End
203
+ } ,
204
+ cancellationToken : ct
205
+ ) ;
206
+
192
207
await foreach ( var message in subscription . Messages ) {
193
208
switch ( message ) {
194
209
case StreamMessage . Event ( var evnt ) :
@@ -205,15 +220,17 @@ static async Task SubscribeToAllSubscriptionDropped(KurrentDBClient client, Canc
205
220
#region subscribe-to-all-subscription-dropped
206
221
207
222
var checkpoint = await ReadCheckpointAsync ( ) switch {
208
- null => FromAll . Start ,
223
+ null => FromAll . Start ,
209
224
var position => FromAll . After ( position . Value )
210
225
} ;
211
226
212
227
Subscribe :
213
228
try {
214
229
await using var subscription = client . SubscribeToAll (
215
- checkpoint ,
216
- cancellationToken : ct ) ;
230
+ new SubscribeToAllOptions { Start = checkpoint } ,
231
+ cancellationToken : ct
232
+ ) ;
233
+
217
234
await foreach ( var message in subscription . Messages ) {
218
235
switch ( message ) {
219
236
case StreamMessage . Event ( var evnt ) :
@@ -243,16 +260,18 @@ static async Task SubscribeToFiltered(KurrentDBClient client, CancellationToken
243
260
244
261
var prefixStreamFilter = new SubscriptionFilterOptions ( StreamFilter . Prefix ( "test-" , "other-" ) ) ;
245
262
await using var subscription = client . SubscribeToAll (
246
- FromAll . Start ,
247
- filterOptions : prefixStreamFilter ,
248
- cancellationToken : ct ) ;
263
+ new SubscribeToAllOptions { FilterOptions = prefixStreamFilter } ,
264
+ cancellationToken : ct
265
+ ) ;
266
+
249
267
await foreach ( var message in subscription . Messages ) {
250
268
switch ( message ) {
251
269
case StreamMessage . Event ( var evnt ) :
252
270
Console . WriteLine ( $ "Received event { evnt . OriginalEventNumber } @{ evnt . OriginalStreamId } ") ;
253
271
await HandleEvent ( evnt ) ;
254
272
255
273
break ;
274
+
256
275
case StreamMessage . AllStreamCheckpointReached ( var position ) :
257
276
Console . WriteLine ( $ "Checkpoint reached: { position } ") ;
258
277
break ;
@@ -272,9 +291,10 @@ static async Task OverridingUserCredentials(KurrentDBClient client, Cancellation
272
291
#region overriding-user-credentials
273
292
274
293
await using var subscription = client . SubscribeToAll (
275
- FromAll . Start ,
276
- userCredentials : new UserCredentials ( "admin" , "changeit" ) ,
277
- cancellationToken : ct ) ;
294
+ new SubscribeToAllOptions { UserCredentials = new UserCredentials ( "admin" , "changeit" ) } ,
295
+ cancellationToken : ct
296
+ ) ;
297
+
278
298
await foreach ( var message in subscription . Messages ) {
279
299
switch ( message ) {
280
300
case StreamMessage . Event ( var evnt ) :
0 commit comments