forked from Aaronontheweb/InMemoryCQRSReplication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StockShardMsgRouter.cs
48 lines (42 loc) · 1.33 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
42
43
44
45
46
47
48
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;
}
switch (message)
{
case ConfirmableMessage<Ask> a:
return a.Message.StockId;
case ConfirmableMessage<Bid> b:
return b.Message.StockId;
case ConfirmableMessage<Fill> f:
return f.Message.StockId;
case ConfirmableMessage<Match> m:
return m.Message.StockId;
}
return null;
}
}
}