ActorSink.actorRefWithBackpressure
Sends the elements of the stream to the given ActorRef[T]
of the new actors API with backpressure, to be able to signal demand when the actor is ready to receive more elements.
Dependency
The Akka dependencies are available from Akka’s library repository. To access them there, you need to configure the URL for this repository.
This operator is included in:
- sbt
val AkkaVersion = "2.10.2" libraryDependencies += "com.typesafe.akka" %% "akka-stream-typed" % AkkaVersion
- Maven
- Gradle
Signature
ActorSink.actorRefWithBackpressure
Description
Sends the elements of the stream to the given ActorRef[T]
with backpressure, to be able to signal demand when the actor is ready to receive more elements. There is also a variant without a concrete acknowledge message accepting any message as such.
See also:
ActorSink.actorRef
Send elements to an actor of the new actors API, without considering backpressureSink.actorRef
Send elements to an actor of the classic actors API, without considering backpressureSink.actorRefWithBackpressue
The corresponding operator for the classic actors API
Examples
- Scala
-
source
import akka.actor.typed.ActorRef import akka.stream.scaladsl.{ Sink, Source } import akka.stream.typed.scaladsl.ActorSink trait Ack object Ack extends Ack trait Protocol case class Init(ackTo: ActorRef[Ack]) extends Protocol case class Message(ackTo: ActorRef[Ack], msg: String) extends Protocol case object Complete extends Protocol case class Fail(ex: Throwable) extends Protocol val actor: ActorRef[Protocol] = targetActor() val sink: Sink[String, NotUsed] = ActorSink.actorRefWithBackpressure( ref = actor, messageAdapter = (responseActorRef: ActorRef[Ack], element) => Message(responseActorRef, element), onInitMessage = (responseActorRef: ActorRef[Ack]) => Init(responseActorRef), ackMessage = Ack, onCompleteMessage = Complete, onFailureMessage = (exception) => Fail(exception)) Source.single("msg1").runWith(sink)
- Java
Reactive Streams semantics
cancels when the actor terminates
backpressures when the actor acknowledgement has not arrived