Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Akka actor that takes another ActorRef as a constructor argument, and forwards all incoming messages to the one passed in. This is useful for unit tests, where you can pass in a JavaTestKit instance to the constructor and all messages passed to this actor will be forwarded to the JavaTestKit instance.
package com.turbo.akka;
* Simple actor that takes another actor and forwards all messages to it.
* Useful in unit testing for capturing and testing if a message was received.
* Simply pass in an Akka JavaTestKit probe into the constructor, and all messages
* that are sent to this actor are forwarded to the JavaTestKit probe
public class ForwarderActor extends UntypedActor {
final ActorRef target;
public ForwarderActor(ActorRef target) { = target;
public void onReceive(Object msg) {
target.forward(msg, getContext());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment