2017-05-07 97 views
0

經過最近的調查和Stack over flow question我意識到集羣分片比集羣一致性哈希路由器更好。但是我無法獲得2個進程集羣。集羣分片客戶端未與主機連接

一個過程是種子,另一個過程是客戶端。種子節點似乎不斷地丟出死信(見本問題的結尾)。

這種子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://[email protected]:5000"] 
    roles = ["Seed"] 

    sharding { 
     journal-plugin-id = "akka.persistence.sharding" 
     snapshot-plugin-id = "akka.snapshot-store.sharding" 
    } 
}} 

我有一個實質上是將上述成配置像這樣的方法:

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://[email protected]:5000"] 
    roles = ["Client"] 
    role.["Seed"].min-nr-of-members = 1 
    sharding { 
     journal-plugin-id = "akka.persistence.sharding" 
     snapshot-plugin-id = "akka.snapshot-store.sharding" 
    } 
}} 

該種子節點創建分片像這樣:

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] [2017年7月5日上午09點○○分58秒] [線程技術[阿卡://我-cluster-system/user/sharding /company-routerCoordinator/singleton/coordinator]消息從akka.tcp註冊 ://[email protected]:5000/user/sharding/company-router to akka: // my-cl uster-system/user/sharding/company-routerCoordinator/singleton/coordinator是否已送達 。遇到4個死信。

Ps。我不使用燈塔。

回答

0

從快速的樣子可以看出,您正在客戶端節點上啓動集羣分片代理,並告訴它分片節點是那些使用種子角色的分區。這與您未指定任何角色時種子節點上的羣集分片定義不匹配。

由於沒有限制它的作用,因此種子節點上的羣集分片將把羣集中的所有節點視爲完全能夠託管分片角色 - 包括沒有羣集分片(非代理)的客戶機節點,實例化它。

這可能不是唯一的問題,但你可以在所有節點的任何主機羣集分片,或者使用ClusterShardingSettings.Create(system).WithRole("seed")你的碎片只限制節點(有種子角色)集羣中的特定子集。

0

由於Horusiath,這是固定它:

return sharding.Start(
    typeName: "company-router", 
    entityProps: Props.Create(() => new CompanyDeliveryActor()),      
    settings: ClusterShardingSettings.Create(system).WithRole("Seed"), 
       messageExtractor: new RouteExtractor(100)     
      ); 

聚集碎片現在是2個進程之間進行通信。非常感謝那一點。

相關問題