-1

Let's say I have a Source:

val source = Source(List(1,2,3))

How can I message the source like an actor?

sourceActor ! 4

1 Answers1

3

You can't use simple collection-based source like that. You need another one like Source.actorRef or Source.queue. Keep in mind that using Source.actorRef does not give you backpressure and that messages send remotely over the network may get lost (due to at-most-once delivery semantic of actor communication).

Also, there's an entire section in Akka documentation about integrating actors.

Bartosz Sypytkowski
  • 7,463
  • 19
  • 36
  • I haven't gave you a down vote. Also sorry, if you'll find my message insufficient, but I've assumed that you're familiar with how does akka.stream work. Every source needs to be materialized with some context - without it it's useless. When done that, it will return a materialized value, which is case of `Source.actorRef` is an `ActorRef` representation of that source. – Bartosz Sypytkowski Nov 28 '17 at 09:23