问题
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.
- 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. - you can import
akka.event.Logging
and putval 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