-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumerGrain.cs
More file actions
47 lines (37 loc) · 1.31 KB
/
ConsumerGrain.cs
File metadata and controls
47 lines (37 loc) · 1.31 KB
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
44
45
46
47
namespace OrleansPersistentStream_DroppedEvents
{
using Orleans.Runtime;
using Orleans.Streams;
[ImplicitStreamSubscription("ns")]
internal class ConsumerGrain : Grain, IConsumerGrain
{
private int lastSeenEvent = 0;
public override async Task OnActivateAsync(CancellationToken cancellationToken)
{
await this.GetStreamProvider("TestStream")
.GetStream<int>(StreamId.Create("ns", this.GetPrimaryKey()))
.SubscribeAsync(this);
await base.OnActivateAsync(cancellationToken);
}
public Task OnNextAsync(int item, StreamSequenceToken? token = null)
{
if (item != this.lastSeenEvent + 1)
{
Console.WriteLine(
$"Skipped events detected. Last observed event is {this.lastSeenEvent} but received event is {item}.");
}
this.lastSeenEvent = item;
Console.WriteLine($"Updated last observed event to: {item}.");
return Task.CompletedTask;
}
public Task OnCompletedAsync()
{
return Task.CompletedTask;
}
public Task OnErrorAsync(Exception ex)
{
Console.WriteLine("Got error");
return Task.CompletedTask;
}
}
}