微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Akka.Net 在同一网络内的不同机器上集群不同的 Actor但是actorsystems无法找到彼此 1.) pc 一:后端,灯塔在 pc2 上:

如何解决Akka.Net 在同一网络内的不同机器上集群不同的 Actor但是actorsystems无法找到彼此 1.) pc 一:后端,灯塔在 pc2 上:

我使用以下设置。在同一网络内的两台不同的 PC 上,我想在第一台运行一个后端产品。个人电脑 而 Gui 部分在 2 日运行。个人电脑。

  1. PC 1 和 Pc 2 使用不同的静态 IP 地址。

  2. 后端产品维护一个 ActorSystem名称:ProductXY-ActorSystem

  3. Gui 产品正在维护第二个 ActorSystem名称:ProductXY-ActorSystem

  4. Lighthouse 在 pc one 上运行,后端正在运行。

  5. 我通过 Cluster.Tools 使用 Publish/Subscibe 进行通信。

请在下面找到我使用的配置文件

1.) pc 一:(后端,灯塔)

---- backend.config

akka {
  stdout-loglevel = INFO
  loglevel = INFO
  ACTOR_SYstem ="ProductXY-ActorSystem"

  actor {
      serialize-messages = on

      debug {
              receive = on      # log any received message
              autoreceive = on  # log automatically received messages,e.g. PoisonPill
              lifecycle = on    # log actor lifecycle changes
              event-stream = on # log subscription changes for Akka.NET event stream
              unhandled = on    # log unhandled messages sent to actors
      }

      provider = "Akka.Cluster.ClusteractorRefProvider,Akka.Cluster"

      serializers {
          hyperion = "Akka.Serialization.HyperionSerializer,Akka.Serialization.Hyperion"
          akka-pubsub = "Akka.Cluster.Tools.PublishSubscribe.Serialization.distributedPubSubMessageSerializer,Akka.Cluster.Tools"
      }

      serialization-bindings {
          "System.Object" = hyperion
          "Akka.Cluster.Tools.PublishSubscribe.IdistributedPubSubMessage,Akka.Cluster.Tools" = akka-pubsub
          "Akka.Cluster.Tools.PublishSubscribe.Internal.SendToOnesubscriber,Akka.Cluster.Tools" = akka-pubsub
      }

      serialization-identifiers {
          "Akka.Cluster.Tools.PublishSubscribe.Serialization.distributedPubSubMessageSerializer,Akka.Cluster.Tools" = 9
      }
  }

  remote {
      log-remote-lifecycle-events = off

      dot-netty.tcp {
          transport-class = "Akka.Remote.Transport.DotNetty.TcpTransport,Akka.Remote"
          applied-adapters = []
          transport-protocol = tcp

          port = 0
          hostname = "10.190.191.20" # <<-- IP to backend pc.
      }
  }

  cluster {
      roles = ["shared-cluster"]
      seed-nodes = ["akka.tcp://"${akka.ACTOR_SYstem}"@10.190.191.20:4053"]# <<-- IP to backend pc.
  }
}

--------灯塔.config

lighthouse{
actorsystem: "ProductXY-ActorSystem"
}

akka {
actor {
  provider = cluster

  serializers {
      hyperion = "Akka.Serialization.HyperionSerializer,Akka.Serialization.Hyperion"
      akka-pubsub = "Akka.Cluster.Tools.PublishSubscribe.Serialization.distributedPubSubMessageSerializer,Akka.Cluster.Tools"
  }

  serialization-bindings {
      "System.Object" = hyperion
      "Akka.Cluster.Tools.PublishSubscribe.IdistributedPubSubMessage,Akka.Cluster.Tools" = akka-pubsub
      "Akka.Cluster.Tools.PublishSubscribe.Internal.SendToOnesubscriber,Akka.Cluster.Tools" = akka-pubsub
  }

  serialization-identifiers {
      "Akka.Cluster.Tools.PublishSubscribe.Serialization.distributedPubSubMessageSerializer,Akka.Cluster.Tools" = 9
  }
}

remote {
  log-remote-lifecycle-events = DEBUG
  dot-netty.tcp {
    transport-class = "Akka.Remote.Transport.DotNetty.TcpTransport,Akka.Remote"
    applied-adapters = []
    transport-protocol = tcp
    #will be populated with a dynamic host-name at runtime if left uncommented
    public-hostname = "10.190.191.20" # <<-- IP to backend pc.
    port = 4053
  }
}            

cluster {
  #will inject this node as a self-seed node at run-time
  seed-nodes = [] 
  roles = [lighthouse]
}
}

在 pc2 上:

-------- Gui.config
  akka {
    stdout-loglevel = INFO
    loglevel = INFO
    ACTOR_SYstem ="ProductXY-ActorSystem"

    actor {
        serialize-messages = on

        debug {
                receive = on      # log any received message
                autoreceive = on  # log automatically received messages,e.g. PoisonPill
                lifecycle = on    # log actor lifecycle changes
                event-stream = on # log subscription changes for Akka.NET event stream
                unhandled = on    # log unhandled messages sent to actors
        }

        provider = "Akka.Cluster.ClusteractorRefProvider,Akka.Cluster"

        serializers {
            hyperion = "Akka.Serialization.HyperionSerializer,Akka.Serialization.Hyperion"
            akka-pubsub = "Akka.Cluster.Tools.PublishSubscribe.Serialization.distributedPubSubMessageSerializer,Akka.Cluster.Tools"
        }

        serialization-bindings {
            "System.Object" = hyperion
            "Akka.Cluster.Tools.PublishSubscribe.IdistributedPubSubMessage,Akka.Cluster.Tools" = akka-pubsub
            "Akka.Cluster.Tools.PublishSubscribe.Internal.SendToOnesubscriber,Akka.Cluster.Tools" = akka-pubsub
        }

        serialization-identifiers {
            "Akka.Cluster.Tools.PublishSubscribe.Serialization.distributedPubSubMessageSerializer,Akka.Cluster.Tools" = 9
        }
    }

    remote {
        log-remote-lifecycle-events = off

        dot-netty.tcp {
            transport-class = "Akka.Remote.Transport.DotNetty.TcpTransport,Akka.Remote"
            applied-adapters = []
            transport-protocol = tcp

            port = 0
            hostname = "10.168.4.30" # <<-- IP to gui pc.
        }
    }

    cluster {
        roles = ["shared-cluster"]
        seed-nodes = ["akka.tcp://"${akka.ACTOR_SYstem}"@10.190.191.20:4053"] # <<-- IP to backend pc.
    }
}

总结: 在后端 pc 上:灯塔和后端产品协同工作得很好。 但是 pc 2 上的 Gui-Product 无法连接到 pc 1 上的灯塔。 在 pc1 上 1 可以 ping pc2,反之亦然。

附加测试:lighthouse、后端和Gui-product在一台IP设置为127.0.0.1的机器上一起运行没有问题。

问:我的 hocon 配置文件有什么问题?

克里斯

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。