forked from petabridge/akkadotnet-cluster-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StockShardMsgRouter.cs
41 lines (35 loc) · 1.06 KB
/
StockShardMsgRouter.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
using System;
using Akka.Cluster.Sharding;
using Akka.CQRS.Events;
using Akka.Persistence.Extras;
namespace Akka.CQRS.Infrastructure
{
/// <summary>
/// Used to route sharding messages to order book actors hosted via Akka.Cluster.Sharding.
/// </summary>
public sealed class StockShardMsgRouter : HashCodeMessageExtractor
{
/// <summary>
/// 3 nodes hosting order books, 10 shards per node.
/// </summary>
public const int DefaultShardCount = 30;
public StockShardMsgRouter() : this(DefaultShardCount)
{
}
public StockShardMsgRouter(int maxNumberOfShards) : base(maxNumberOfShards)
{
}
public override string EntityId(object message)
{
if (message is IWithStockId stockMsg)
{
return stockMsg.StockId;
}
if (message is IConfirmableMessageEnvelope<IWithStockId> envelope)
{
return envelope.Message.StockId;
}
return null;
}
}
}