经过最近的调查和Stack over flow question我意识到群集分片比群集一致哈希路由器更好。但我无法获得2个进程集群。
一个进程是Seed,另一个进程是Client。 Seed节点似乎不断抛出死信信息(参见本期末)。
此种子HOCON如下:
akka {
loglevel = "INFO"
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
serializers {
wire = "Akka.Serialization.WireSerializer, Akka.Serialization.Wire"
}
serialization-bindings {
"System.Object" = wire
}
}
remote {
dot-netty.tcp {
hostname = "127.0.0.1"
port = 5000
}
}
persistence {
journal {
plugin = "akka.persistence.journal.sql-server"
sql-server {
class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
schema-name = dbo
auto-initialize = on
connection-string = "Data Source=localhost;Integrated Security=True;MultipleActiveResultSets=True;Initial Catalog=ClusterExperiment01"
plugin-dispatcher = "akka.actor.default- dispatcher"
connection-timeout = 30s
table-name = EventJournal
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
metadata-table-name = Metadata
}
}
sharding {
connection-string = "Data Source=localhost;Integrated Security=True;MultipleActiveResultSets=True;Initial Catalog=ClusterExperiment01"
auto-initialize = on
plugin-dispatcher = "akka.actor.default-dispatcher"
class = "Akka.Persistence.SqlServer.Journal.SqlServerJournal, Akka.Persistence.SqlServer"
connection-timeout = 30s
schema-name = dbo
table-name = ShardingJournal
timestamp-provider = "Akka.Persistence.Sql.Common.Journal.DefaultTimestampProvider, Akka.Persistence.Sql.Common"
metadata-table-name = ShardingMetadata
}
}
snapshot-store {
sharding {
class = "Akka.Persistence.SqlServer.Snapshot.SqlServerSnapshotStore, Akka.Persistence.SqlServer"
plugin-dispatcher = "akka.actor.default-dispatcher"
connection-string = "Data Source=localhost;Integrated Security=True;MultipleActiveResultSets=True;Initial Catalog=ClusterExperiment01"
connection-timeout = 30s
schema-name = dbo
table-name = ShardingSnapshotStore
auto-initialize = on
}
}
cluster {
seed-nodes = ["akka.tcp://my-cluster-system@127.0.0.1:5000"]
roles = ["Seed"]
sharding {
journal-plugin-id = "akka.persistence.sharding"
snapshot-plugin-id = "akka.snapshot-store.sharding"
}
}}
我有一种方法,基本上将上述内容转换为Config,如下所示:
var config = NodeConfig.Create(/* HOCON above */).WithFallback(ClusterSingletonManager.DefaultConfig());
没有" WithFallback"我从配置生成中得到一个空引用异常。
然后像这样生成系统:
var system = ActorSystem.Create("my-cluster-system", config);
客户以相同的方式创建系统,HOCON几乎完全相同:
{
remote {
dot-netty.tcp {
hostname = "127.0.0.1"
port = 5001
}
}
cluster {
seed-nodes = ["akka.tcp://my-cluster-system@127.0.0.1:5000"]
roles = ["Client"]
role.["Seed"].min-nr-of-members = 1
sharding {
journal-plugin-id = "akka.persistence.sharding"
snapshot-plugin-id = "akka.snapshot-store.sharding"
}
}}
Seed节点创建分片,如下所示:
ClusterSharding.Get(system).Start(
typeName: "company-router",
entityProps: Props.Create(() => new CompanyDeliveryActor()),
settings: ClusterShardingSettings.Create(system),
messageExtractor: new RouteExtractor(100)
);
客户端创建一个像这样的分片代理:
ClusterSharding.Get(system).StartProxy(
typeName: "company-router",
role: "Seed",
messageExtractor: new RouteExtractor(100));
RouteExtractor是:
public class RouteExtractor : HashCodeMessageExtractor
{
public RouteExtractor(int maxNumberOfShards) : base(maxNumberOfShards)
{
}
public override string EntityId(object message) => (message as IHasRouting)?.Company?.VolumeId.ToString();
public override object EntityMessage(object message) => message;
}
在这种情况下,VolumeId始终是相同的(仅用于实验)。
这两个进程都生效,但种子不断将此错误抛给日志:
[INFO] [7/05/2017 9:00:58 AM] [Thread 0003] [akka:// my-cluster-system / user / sharding / company-routerCoordinator / singleton / coordinator]消息从akka.tcp注册 ://my-cluster-system@127.0.0.1:5000 / user / sharding / company-router to akka:// my-cl uster-system / user / sharding / company-routerCoordinator / singleton / coordinator是n 交付。遇到4封死信。
聚苯乙烯。我不是在使用Lighthouse。
答案 0 :(得分:0)
从快速查看,您在客户端节点上启动群集分片代理,并且您告诉它分片节点是那些使用种子角色的节点。当您尚未指定任何角色时,这与种子节点上的群集分片定义不匹配。
由于没有限制它的角色,种子节点上的群集分片会将群集中的所有节点视为完全能够托管分片角色 - 包括客户端节点,它没有群集分片(非代理) )实例化它。
这可能不是唯一的问题,但您可以在所有节点上托管群集分片,或使用ClusterShardingSettings.Create(system).WithRole("seed")
将分片限制为特定的节点子集(具有种子集群中的em> role。