6
votes

I'm using an ActorPublisher as an Akka-Stream Source. I can't figure out how to predictably name the input actor so I can send it messages from other parts of my application. I'm instantiating my source like so:

val src = Source[Task](Props(classOf[TaskListener], this), "task-listener")

I get an ActorRef when I materialize the stream, but the path for it is dynamically generated, and it only uses my provided name as part of a code-generated flow-centric naming scheme.

Is there any way to have this front-end actor source have an explicit name or am I stuck passing the ActorRef around?

If I can't explicitly name it does this mean you can't use Akka-Stream directly with remoting?

EDIT: I can find my actor using relative pathing now, but I still need to figure out how to name my Flow so I can understand what the full path to the actor in question will be.

EDIT: (akka version info below, scala 2.11.6)

"com.typesafe.akka" %% "akka-actor" % "2.3.9"
"com.typesafe.akka" %% "akka-stream-experimental" % "1.0-M4"

EDIT: The friendly folks over at the akka-user google group have enlightened me, and suggest that the proper way to deal with this is by passing around the ActorRef that results from the runWith() call itself and not using .actorSelection(). I will update this question if I find that this state of affairs changes in the future. Thanks for reading.

1
I understand that over 3 years passed, but could you please share the way you dealed with this finally, because I struggle with the exact same taskYoZH
@YoZH I created a Source using Source.actorPublisher, then created a Flow on which i called flow.runWith(src) -- but that method has been deprecated since. Hopefully you have navigated your way around the problem by now.Rich Henry

1 Answers

2
votes

Good way to solve this, will be adding Group router with specific path, then you can tell router where it can find you actors (routees).

By doing this you will decouple your concrete actor group and maintain single point of entry to your Source pool via router. Also you will be able to make this router cluster aware in future.

You can also look into ActorFlowMaterializer - http://doc.akka.io/api/akka-stream-and-http-experimental/1.0-M5/index.html#akka.stream.ActorFlowMaterializer itself. You can find this comment in source code:

/** The `namePrefix` is used as the first part of the names of the actors running
  * the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of
  * `namePrefix-flowNumber-flowStepNumber-stepName`.
  */
def create(settings: ActorFlowMaterializerSettings, context: ActorRefFactory, namePrefix: String): ActorFlowMaterializer =
apply(Option(settings), Option(namePrefix))(context)