actorRefWithAck
Materialize an ActorRef
; sending messages to it will emit them on the stream. The source acknowledges reception after emitting a message, to provide back pressure from the source.
Description
Materialize an ActorRef
, sending messages to it will emit them on the stream. The actor responds with the provided ack message once the element could be emitted alowing for backpressure from the source. Sending another message before the previous one has been acknowledged will fail the stream.
emits when there is demand and there are messages in the buffer or a message is sent to the ActorRef
completes when the ActorRef
is sent akka.actor.Status.Success
Examples
- Scala
-
source
import akka.actor.Status.Success import akka.actor.ActorRef import akka.stream.CompletionStrategy import akka.stream.scaladsl._ implicit val system: ActorSystem = ActorSystem() implicit val materializer: ActorMaterializer = ActorMaterializer() val probe = TestProbe() val source: Source[Any, ActorRef] = Source.actorRefWithAck[Any]("ack") val actorRef: ActorRef = source.to(Sink.foreach(println)).run() probe.send(actorRef, "hello") probe.expectMsg("ack") probe.send(actorRef, "hello") probe.expectMsg("ack") // The stream completes successfully with the following message actorRef ! Success(CompletionStrategy.immediately) - Java