0

首先,对不起我的英语。谷歌翻译对我帮助很大,哈哈。

我的问题是这样的:

我有两个使用akkaand开发的示例项目java:example-remote-client.jar 和 example-remote-server.jar

我正在使用动脉序列化,并且我正在尝试通过 akka-remoting 从客户端向服务器发送消息。

执行此操作的客户端参与者是:

public class ClientActor extends AbstractActor {

    public static Props props() {
        return Props.create(ClientActor.class);

    }

    public ClientActor() {
        ActorSelection selection = getContext().system().actorSelection("akka://server@localhost:5001/user/server-process");
        selection.tell(new MessageRequest(), getSelf());
    }

    public Receive createReceive() {
        return receiveBuilder().match(MessageResponse.class, msg -> {
            System.out.println(msg.getMessage());
        }).build();
    }
}

我的客户端配置:

akka {
  loglevel = "DEBUG"

  actor {
    provider = remote
    allow-java-serialization = off


    serializers {
      java = "akka.serialization.JavaSerializer"
      myown = "serializers.ExampleByteBufSerializer"
    }

    serialization-bindings {
      "java.lang.String" = myown
      "protocol.MessageRequest" = myown
      "protocol.MessageResponse" = myown
      "java.lang.Boolean" = myown
    }

  }

  remote {
    artery {
      enabled = on
      canonical.hostname = "192.168.0.250"     # external (logical) hostname
      canonical.port = 5000                   # external (logical) port

      bind.hostname = "localhost" # internal (bind) hostname
      bind.port = 10000              # internal (bind) port
    }
  }
}

服务器演员很假,我认为没有必要在这里粘贴。但它的配置是:

akka {
  loglevel = "DEBUG"

  actor {
    provider = remote
    allow-java-serialization = off


    serializers {
      java = "akka.serialization.JavaSerializer"
      myown = "serializers.ExampleByteBufSerializer"
    }

    serialization-bindings {
      "java.lang.String" = myown
      "protocol.MessageRequest" = myown
      "protocol.MessageResponse" = myown
      "java.lang.Boolean" = myown
    }

  }

  remote {
    artery {
      enabled = on
      canonical.hostname = "192.168.0.250"     # external (logical) hostname
      canonical.port = 5001                   # external (logical) port

      bind.hostname = "localhost" # internal (bind) hostname
      bind.port = 10001              # internal (bind) port
    }
  }
}

两个 jar 都部署在运行在同一“192.168.0.250 机器”上的 docker 实例上,如下所示:

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                                            NAMES
d2970bd20371        openjdk:alpine             "sh"                     34 minutes ago      Up 34 minutes       0.0.0.0:5001->10001/tcp                          ex-remoting-server
36a67fea8590        openjdk:alpine             "sh"                     34 minutes ago      Up 34 minutes       0.0.0.0:5000->10000/tcp                          ex-remoting-client

服务器启动正常,日志如下:

[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] logger log1-Logging$DefaultLogger started
[DEBUG] [07/04/2017 13:46:18.473] [main] [EventStream(akka://server)] Default Loggers started
[DEBUG] [07/04/2017 13:46:18.495] [main] [akka.serialization.Serialization(akka://server)] Replacing JavaSerializer with DisabledJavaSerializer, due to `akka.actor.allow-java-serialization = off`.
[INFO] [07/04/2017 13:46:18.628] [main] [akka.remote.artery.ArteryTransport(akka://server)] Started embedded media driver in directory [/dev/shm/aeron-root-server-efd42dec-452d-406c-8d1d-807e0d8ff7fc]
[INFO] [07/04/2017 13:46:18.693] [main] [akka.remote.artery.ArteryTransport(akka://server)] Remoting started; listening on address: [akka://server@192.168.0.250:5001] with UID [-2663186266051514585]

但是当我尝试启动客户端时,出现以下错误:

[ERROR] [07/04/2017 14:09:05.250] [client-akka.actor.default-dispatcher-10] [akka://server@192.168.0.250:5001/] swallowing exception during message send
io.aeron.exceptions.RegistrationException: Insufficient usable storage for new log of length=50332096 in /dev/shm (shm)
    at io.aeron.ClientConductor.onError(ClientConductor.java:285)
    at io.aeron.DriverListenerAdapter.onMessage(DriverListenerAdapter.java:79)
    at org.agrona.concurrent.broadcast.CopyBroadcastReceiver.receive(CopyBroadcastReceiver.java:100)
    at io.aeron.DriverListenerAdapter.pollMessage(DriverListenerAdapter.java:59)
    at io.aeron.ClientConductor.doWork(ClientConductor.java:422)
    at io.aeron.ClientConductor.awaitResponse(ClientConductor.java:447)
    at io.aeron.ClientConductor.addPublication(ClientConductor.java:177)
    at io.aeron.Aeron.addPublication(Aeron.java:165)
    at akka.remote.artery.AeronSink$$anon$1.<init>(AeronSink.scala:103)
    at akka.remote.artery.AeronSink.createLogicAndMaterializedValue(AeronSink.scala:100)
    at akka.stream.impl.GraphStageIsland.materializeAtomic(PhasedFusingActorMaterializer.scala:627)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:458)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:420)
    at akka.stream.impl.PhasedFusingActorMaterializer.materialize(PhasedFusingActorMaterializer.scala:415)
    at akka.stream.scaladsl.RunnableGraph.run(Flow.scala:439)
    at akka.remote.artery.Association.akka$remote$artery$Association$$runOutboundOrdinaryMessagesStream(Association.scala:570)
    at akka.remote.artery.Association.runOutboundStreams(Association.scala:510)
    at akka.remote.artery.Association.associate(Association.scala:502)
    at akka.remote.artery.AssociationRegistry.association(Association.scala:763)
    at akka.remote.artery.ArteryTransport.association(ArteryTransport.scala:932)
    at akka.remote.artery.ArteryTransport.send(ArteryTransport.scala:918)
    at akka.remote.RemoteActorRef.$bang(RemoteActorRefProvider.scala:563)
    at akka.actor.ActorRef.tell(ActorRef.scala:124)
    at akka.actor.ActorSelection$.rec$1(ActorSelection.scala:250)
    at akka.actor.ActorSelection$.deliverSelection(ActorSelection.scala:254)
    at akka.actor.ActorSelection.tell(ActorSelection.scala:45)
    at actors.ClientActor.<init>(ClientActor.java:21)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at akka.util.Reflect$.instantiate(Reflect.scala:44)
    at akka.actor.NoArgsReflectConstructor.produce(IndirectActorProducer.scala:105)
    at akka.actor.Props.newActor(Props.scala:213)
    at akka.actor.ActorCell.newActor(ActorCell.scala:563)
    at akka.actor.ActorCell.create(ActorCell.scala:589)
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:462)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:484)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282)
    at akka.dispatch.Mailbox.run(Mailbox.scala:223)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
    at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

我还尝试使用这些“ActorSelection 路径”发送消息:

"akka://server@192.168.0.250:5001/user/server-process" "akka://server@localhost:5001/user/server-process" "akka://server@192.168.0.250:10001/user /server-process" "akka://server@localhost:10001/user/server-process"

但错误仍然出现。

同样重要的是要澄清服务器参与者的参与者路径是:

akka://server/user/server-process

什么不见​​了?我正在使用 akka 2.5.3 版本...

谢谢。

4

2 回答 2

2

我不太确定 Akka 规范与绑定寻址是如何工作的。但我的猜测是,它bind.hostname是实际 IP 或通过它将侦听的主机名解析的 IP。在这种情况下,localhost转换为127.0.0.1,这意味着容器将只接受 上的连接127.0.0.1

尝试将 设置bind.hostname0.0.0.0。这将允许来自容器外部 IP 地址的连接(从主机通过端口 5001)。

于 2017-07-04T16:13:10.840 回答
0

尝试将/dev/shm卷的大小设置得更大。在 docker-compose 文件中,您可以简单地添加此选项:shm_size: 500M. 此卷是 aeron 用于缓冲消息的共享内存空间。

于 2017-10-27T21:42:00.513 回答