more docs for Sink.queue and actorRefWithAck (#25063)
This commit is contained in:
parent
8f40dc7f03
commit
de04758bb8
7 changed files with 118 additions and 9 deletions
|
|
@ -9,24 +9,21 @@ import akka.NotUsed
|
|||
import scala.concurrent.duration._
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.stream.scaladsl._
|
||||
import akka.stream.ActorMaterializer
|
||||
import akka.stream._
|
||||
|
||||
import scala.concurrent.Future
|
||||
import akka.testkit.TestProbe
|
||||
import akka.actor.{ Actor, ActorLogging, ActorRef, Props, Status }
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import akka.util.Timeout
|
||||
import akka.stream.Attributes
|
||||
import akka.stream.ActorAttributes
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
import akka.stream.ActorMaterializerSettings
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import akka.stream.Supervision
|
||||
import akka.stream.scaladsl.Flow
|
||||
import akka.Done
|
||||
import akka.actor.Status.Status
|
||||
import akka.stream.QueueOfferResult.{ Dropped, Enqueued }
|
||||
|
||||
object IntegrationDocSpec {
|
||||
import TwitterStreamQuickstartDocSpec._
|
||||
|
|
@ -476,4 +473,30 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
|
|||
"after: J"))
|
||||
}
|
||||
|
||||
"illustrate use of source queue" in {
|
||||
//#source-queue
|
||||
val bufferSize = 5
|
||||
val elementsToProcess = 3
|
||||
|
||||
val queue = Source
|
||||
.queue[Int](bufferSize, OverflowStrategy.backpressure)
|
||||
.throttle(elementsToProcess, 3.second)
|
||||
.map(x ⇒ x * x)
|
||||
.toMat(Sink.foreach(x ⇒ println(s"completed $x")))(Keep.left)
|
||||
.run()
|
||||
|
||||
val source = Source(1 to 10)
|
||||
|
||||
implicit val ec = system.dispatcher
|
||||
source.mapAsync(1)(x ⇒ {
|
||||
queue.offer(x).map {
|
||||
case QueueOfferResult.Enqueued ⇒ println(s"enqueued $x")
|
||||
case QueueOfferResult.Dropped ⇒ println(s"dropped $x")
|
||||
case QueueOfferResult.Failure(ex) ⇒ println(s"Offer failed ${ex.getMessage}")
|
||||
case QueueOfferResult.QueueClosed ⇒ println("Source Queue closed")
|
||||
}
|
||||
}).runWith(Sink.ignore)
|
||||
//#source-queue
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue