Akka IO(Tcp) get reason of CommandFailed

有些话、适合烂在心里 提交于 2020-01-16 05:25:07

问题


I have the following example of Actor using IO(Tcp) https://gist.github.com/flirtomania/a36c50bd5989efb69a5f

For the sake of experiment I've run it twice, so it was trying to bind to 803 port. Obviously I've got an error.

Question: How can I get the reason why "CommandFailed"? In application.conf I have enabled slf4j and debug level of logs, then I've got an error in my logs.

DEBUG akka.io.TcpListener - Bind failed for TCP channel on endpoint [localhost/127.0.0.1:803]: java.net.BindException: Address already in use: bind

But why is that only debug level? I do not want to enable all ActorSystem to log their events, I want to get the reason of CommandFailed event (like java.lang.Exception instance which I could make e.printStackTrace())

Something like: case c @ CommandFailed => val e:Exception = c.getReason()

Maybe it's not the Akka-way? How to get diagnostic info then?


回答1:


Here's what you can do - find the PID that still keeps living and then kill it.

On a Mac -

lsof -i : portNumber then kill -9 PidNumber




回答2:


I understood that you have 2 questions.

  1. if you ran the same code simultaneously, bot actors are trying to bind to the same port (in your case, 803) which is not possible unless the bound one unbinds and closes the connection so that the other one can bind.
  2. you can import akka.event.Logging and put val log = Logging(context.system, this) at the beginning of your actors, which will log all the activities of your actors and ... it also shows the name of the actor,corresponding actor system and host+port (if you are using akka-cluster).

wish that helps



来源:https://stackoverflow.com/questions/28478379/akka-iotcp-get-reason-of-commandfailed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!