-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrainA.cs
More file actions
46 lines (35 loc) · 1.31 KB
/
GrainA.cs
File metadata and controls
46 lines (35 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
namespace OrleansStreamingIssue
{
using Orleans;
using Orleans.Streams;
[ImplicitStreamSubscription(Namespace)] // Remove this and re-run to show expected flow.
internal class GrainA : Grain, IGrainA
{
public const string Namespace = "ns";
private IAsyncStream<string>? stream;
public override async Task OnActivateAsync()
{
var streamProvider = this.GetStreamProvider("SimpleMessaging");
this.stream = streamProvider.GetStream<string>(this.GetPrimaryKey(), Namespace);
await this.stream.SubscribeAsync((s, _) =>
{
Console.WriteLine("Grain A received its own message: " + s);
return Task.CompletedTask;
});
}
public async Task SendMessage(string message)
{
await stream!.OnNextAsync(message);
}
public async Task Subscribe(Guid id)
{
var streamProvider = this.GetStreamProvider("SimpleMessaging");
var otherGrainAStream = streamProvider.GetStream<string>(id, Namespace);
await otherGrainAStream.SubscribeAsync((s, _) =>
{
Console.WriteLine("Other Grain A received message: " + s);
return Task.CompletedTask;
});
}
}
}