user2320977
user2320977

Reputation: 15

What is the best way to log all commands and responses in Akka.net?

What would be the best way to log all commands and response from an Akka.net cluster? The logging would be handled by a hierarchy of logger actors, but how would these loggers receive or intercept the various commands and responses? I've tried using the event bus to subscribe to specific commands, but that does not seem to work as I thought, since no command is intercepted.

Upvotes: 1

Views: 502

Answers (1)

Bartosz Sypytkowski
Bartosz Sypytkowski

Reputation: 7542

In Akka.NET every single actor has it's own message queue used to order incoming requests. There are few ways of doing that:

The simplest one is to create your own abstract actor type used by all other actors in your system, and override its AroundReceive method - it will let you to wrap inheriting actors receive handlers with any sort of logic you want:

class AppActor : ActorBase 
{
    protected readonly ILoggingAdapter logger = Context.GetLogger();

    protected override bool AroundReceive(Receive receive, object message) 
    {
        logger.Debug("Incoming request: {0}", message);
        return receive(message);
    }
}

This will also mean, that you need a separate type for every other variant of actors used in your system, like receive actors or persistent actors.

If you want out of the box solution - there's a commercial tool called Phobos, which can collect metrics of all messages in-flight inside of your actor system, log them and even trace causality between them (a.k.a. tracing).

Upvotes: 1

Related Questions