在Akka.NET中,(使用Akka.Cluster)如何配置多个种子节点(Lighthouse)相互了解?

2023-12-27

如果我想让两个 Lighthouse 种子节点在不同的 PC 上运行,每个节点都应该了解另一个节点,我应该如何配置它们?尽管我发现提到使用多个 Lighthouse 实例,并看到使用多个种子节点的非种子节点配置,但我无法在了解一个的单独 PC 上找到多个种子节点(特别是 Lighthouse)的示例其他。

我目前有类似的东西,但我不确定它是否正确。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
    </configSections>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <akka>
        <hocon>
            <![CDATA[
                    lighthouse{
                            actorsystem: "MySystem" #POPULATE NAME OF YOUR ACTOR SYSTEM HERE
                        }

                    akka {
                        actor { 
                            provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
                        }

                        remote {
                            log-remote-lifecycle-events = DEBUG
                            helios.tcp {
                                transport-class = "Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote"
                                applied-adapters = []
                                transport-protocol = tcp
                                #will be populated with a dynamic host-name at runtime if left uncommented
                                #public-hostname = "POPULATE STATIC IP HERE"
                                public-hostname = "192.168.72.55"
                                hostname = "0.0.0.0"
                                port = 4053
                            }
                        }            

                        loggers = ["Akka.Logger.NLog.NLogLogger,Akka.Logger.NLog"]

                        cluster {
                            #will inject this node as a self-seed node at run-time
                            seed-nodes = [
                "akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053"
                "akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053"
              ] #manually populate other seed nodes here, i.e. "akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053", "akka.tcp://[email protected] /cdn-cgi/l/email-protection:4044"
                            roles = [lighthouse]
                        }
                    }
            ]]>
        </hocon>
    </akka>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

与其他实例的配置基本相同,但有以下差异:

akka.remote:

public-hostname = "192.168.72.56"

akka.集群:

    seed-nodes = [
  "akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053"
  "akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053"
] #manually populate other seed nodes here, i.e. "akka.tcp://lig[email protected] /cdn-cgi/l/email-protection:4053", "akka.tcp://[email protected] /cdn-cgi/l/email-protection:4044"

这是正确的吗?有什么我应该改变或可以改进的地方吗?确保一切正常运行的最佳方法是什么?我是否应该删除每个配置中的第一个种子节点,因为注释似乎表明不需要包含它?

如果我在 192.168.72.55 上启动节点,然后在 192.168.72.56 上启动节点,我会看到它在 192.168.72.55 上加入,并在 192.168.72.56 上收到欢迎消息。如果我关闭192.168.72.56实例并再次启动它,它再次受到欢迎,但192.168.72.55实例不断输出消息,例如:

Akka.Cluster.ClusterCoreDaemon: Leader can currently not perform its duties, rea
chability status: [akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053 -> UniqueAddr
ess: (akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053, 1180787153): Unreachable
[Unreachable] (2), ], member status: [$akka.tcp://[email protected] /cdn-cgi/l/email-protection
:4053 $Up seen=$True, $akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053 $Up seen
=$False]
Akka.Remote.MySystem: Association with remote system akka.tcp:
//[email protected] /cdn-cgi/l/email-protection:4053 has failed; address is now gated for 5000
 ms. Reason is: [Akka.Remote.EndpointDisassociatedException: Disassociated
   at Akka.Remote.EndpointWriter.PublishAndThrow(Exception reason, LogLevel leve
l)
   at Akka.Remote.EndpointWriter.Unhandled(Object message)
   at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, Parti
alAction`1 partialAction)
   at Akka.Actor.ReceiveActor.<>c__DisplayClass11_0.<Become>b__0(Object m)
   at Akka.Actor.ActorCell.<>c__DisplayClass109_0.<Akka.Actor.IUntypedActorConte
xt.Become>b__0(Object m)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Akka.Actor.ActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.ReceivedTerminated(Terminated t)
   at Akka.Actor.ActorCell.AutoReceiveMessage(Envelope envelope)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Akka.Actor.ActorCell.HandleFailed(Failed f)
   at Akka.Actor.ActorCell.SystemInvoke(Envelope envelope)]
Akka.Actor.OneForOneStrategy: Disassociated Akka.Remote.EndpointDisassociatedExc
eption: Disassociated
   at Akka.Remote.EndpointWriter.PublishAndThrow(Exception reason, LogLevel leve
l)
   at Akka.Remote.EndpointWriter.Unhandled(Object message)
   at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, Parti
alAction`1 partialAction)
   at Akka.Actor.ReceiveActor.<>c__DisplayClass11_0.<Become>b__0(Object m)
   at Akka.Actor.ActorCell.<>c__DisplayClass109_0.<Akka.Actor.IUntypedActorConte
xt.Become>b__0(Object m)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Akka.Actor.ActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.ReceivedTerminated(Terminated t)
   at Akka.Actor.ActorCell.AutoReceiveMessage(Envelope envelope)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Akka.Actor.ActorCell.HandleFailed(Failed f)
   at Akka.Actor.ActorCell.SystemInvoke(Envelope envelope)

然后:

Akka.Cluster.ClusterCoreDaemon: Leader can currently not perform its duties, reachability status: [], member status: [$akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053 $Up seen=$True, $akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053 $Up seen =$False]
Akka.Remote.ReliableDeliverySupervisor: Association with remote system akka.tcp:
//[email protected] /cdn-cgi/l/email-protection:4053 has failed; address is now gated for 5000
 ms. Reason is: [Akka.Remote.EndpointDisassociatedException: Disassociated
   at Akka.Remote.EndpointWriter.PublishAndThrow(Exception reason, LogLevel leve
l)
   at Akka.Remote.EndpointWriter.Unhandled(Object message)
   at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, Parti
alAction`1 partialAction)
   at Akka.Actor.ReceiveActor.<>c__DisplayClass11_0.<Become>b__0(Object m)
   at Akka.Actor.ActorCell.<>c__DisplayClass109_0.<Akka.Actor.IUntypedActorConte
xt.Become>b__0(Object m)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Akka.Actor.ActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.ReceivedTerminated(Terminated t)
   at Akka.Actor.ActorCell.AutoReceiveMessage(Envelope envelope)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)]
Akka.Actor.OneForOneStrategy: Disassociated Akka.Remote.EndpointDisassociatedExc
eption: Disassociated
   at Akka.Remote.EndpointWriter.PublishAndThrow(Exception reason, LogLevel leve
l)
   at Akka.Remote.EndpointWriter.Unhandled(Object message)
   at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, Parti
alAction`1 partialAction)
   at Akka.Actor.ReceiveActor.<>c__DisplayClass11_0.<Become>b__0(Object m)
   at Akka.Actor.ActorCell.<>c__DisplayClass109_0.<Akka.Actor.IUntypedActorConte
xt.Become>b__0(Object m)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Akka.Actor.ActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.ReceivedTerminated(Terminated t)
   at Akka.Actor.ActorCell.AutoReceiveMessage(Envelope envelope)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Akka.Actor.ActorCell.HandleFailed(Failed f)
   at Akka.Actor.ActorCell.SystemInvoke(Envelope envelope)

再次执行此操作时,我注意到以下消息:

Akka.Cluster.ClusterCoreDaemon: New incarnation of existing member [UniqueAddres
s: (akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053, 1173825306)] is trying to j
oin. Existing will be removed from the cluster and then new member will be allow
ed to join.
Akka.Cluster.ClusterCoreDaemon: Marking node [akka.tcp://[email protected] /cdn-cgi/l/email-protection
8.72.56:4053] as Down
Akka.Cluster.ClusterCoreDaemon: Leader can perform its duties again

Akka.Cluster.ClusterCoreDaemon: New incarnation of existing member [UniqueAddres
s: (akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053, 253329532)] is trying to jo
in. Existing will be removed from the cluster and then new member will be allowe
d to join.
Akka.Cluster.ClusterCoreDaemon: Cluster Node [akka.tcp://[email protected] /cdn-cgi/l/email-protection
8.72.55:4053] - Marking node(s) as UNREACHABLE [Member(address = akka.tcp://Sup
[email protected] /cdn-cgi/l/email-protection:4053, status = Down]
Akka.Cluster.ClusterCoreDaemon: Leader is removing unreachable node [akka.tcp://
[email protected] /cdn-cgi/l/email-protection:4053]
Akka.Event.DummyClassForStringSources: Association to [akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053] having UID [1180787153] is irrecoverably failed. UID is
now quarantined and all messages to this UID will be delivered to dead letters.
Remote actorsystem must be restarted to recover from this situation.
Akka.Remote.ReliableDeliverySupervisor: Association with remote system akka.tcp:
//[email protected] /cdn-cgi/l/email-protection:4053 has failed; address is now gated for 5000
 ms. Reason is: [Akka.Remote.EndpointDisassociatedException: Disassociated
   at Akka.Remote.EndpointWriter.PublishAndThrow(Exception reason, LogLevel leve
l)
   at Akka.Remote.EndpointWriter.Unhandled(Object message)
   at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, Parti
alAction`1 partialAction)
   at Akka.Actor.ReceiveActor.<>c__DisplayClass11_0.<Become>b__0(Object m)
   at Akka.Actor.ActorCell.<>c__DisplayClass109_0.<Akka.Actor.IUntypedActorConte
xt.Become>b__0(Object m)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Akka.Actor.ActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.ReceivedTerminated(Terminated t)
   at Akka.Actor.ActorCell.AutoReceiveMessage(Envelope envelope)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Akka.Actor.ActorCell.HandleFailed(Failed f)
   at Akka.Actor.ActorCell.SystemInvoke(Envelope envelope)]
Akka.Cluster.ClusterCoreDaemon: Node [akka.tcp://[email protected] /cdn-cgi/l/email-protection
:4053] is JOINING, roles [lighthouse]
Akka.Actor.OneForOneStrategy: Disassociated Akka.Remote.EndpointDisassociatedExc
eption: Disassociated
   at Akka.Remote.EndpointWriter.PublishAndThrow(Exception reason, LogLevel leve
l)
   at Akka.Remote.EndpointWriter.Unhandled(Object message)
   at Akka.Actor.ReceiveActor.ExecutePartialMessageHandler(Object message, Parti
alAction`1 partialAction)
   at Akka.Actor.ReceiveActor.<>c__DisplayClass11_0.<Become>b__0(Object m)
   at Akka.Actor.ActorCell.<>c__DisplayClass109_0.<Akka.Actor.IUntypedActorConte
xt.Become>b__0(Object m)
   at Akka.Actor.ActorBase.AroundReceive(Receive receive, Object message)
   at Akka.Actor.ActorCell.ReceiveMessage(Object message)
   at Akka.Actor.ActorCell.ReceivedTerminated(Terminated t)
   at Akka.Actor.ActorCell.AutoReceiveMessage(Envelope envelope)
   at Akka.Actor.ActorCell.Invoke(Envelope envelope)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Akka.Actor.ActorCell.HandleFailed(Failed f)
   at Akka.Actor.ActorCell.SystemInvoke(Envelope envelope)
Akka.Cluster.ClusterCoreDaemon: Leader is moving node [akka.tcp://[email protected] /cdn-cgi/l/email-protection:4053] to [Up]

也许您应该使用 BroadcastRouter 来聚合每个节点。每个节点都应该告诉这个路由器一些类似“我是”的信息。

实际上,每个 BroadcastRouter 的子节点都应该接收具有 Sender 属性的“我是”。

这样,您应该使用这个构造函数:https://github.com/akkadotnet/akka.net/blob/master/src/core/Akka/Routing/Broadcast.cs#L266 https://github.com/akkadotnet/akka.net/blob/master/src/core/Akka/Routing/Broadcast.cs#L266

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在Akka.NET中,(使用Akka.Cluster)如何配置多个种子节点(Lighthouse)相互了解? 的相关文章

随机推荐