Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to the akka streams

Fda899b3499ba4d6b2dbc763b3923759?s=47 s_edward
October 27, 2018

Introduction to the akka streams

Introduction to the akka streams.

Fda899b3499ba4d6b2dbc763b3923759?s=128

s_edward

October 27, 2018
Tweet

Transcript

  1. *OUSPEVDUJPOUP
 UIFBLLBTUSFBNT 4IJHFLJ4IPKJ

  2. w 'SFFMBODFS w *BNHPPEBUDPNQVUFSMBOHVBHF4DBMB +BWB 1ZUIPO $ BOE NPSF w

    5XJUUFS!UBLFTFDUJPO
 -JOLFEJOIUUQTXXXMJOLFEJODPNJOUBLFTFDUJPO

  3. BLLBTUSFBNT w IUUQTEPDBLLBJPEPDTBLLBDVSSFOUTUSFBNJOEFYIUNM w 4JNJMBSQMBUGPSNTJODMVEF3FBDUJWF9 3FBDUJWF4USFBNT
 
 IUUQSFBDUJWFYJP
 IUUQXXXSFBDUJWFTUSFBNTPSH

  4. 4PVSDF w "QSPDFTTJOHTUBHFXJUIFYBDUMZPOFPVUQVU FNJUUJOHEBUB FMFNFOUTXIFOFWFSEPXOTUSFBNQSPDFTTJOHTUBHFTBSFSFBEZUP SFDFJWFUIFN
 
 WBMTPVSDF4PVSDF<*OU /PU6TFE>4PVSDF UP

  5. 4JOL w "QSPDFTTJOHTUBHFXJUIFYBDUMZPOFJOQVU SFRVFTUJOHBOE BDDFQUJOHEBUBFMFNFOUTQPTTJCMZTMPXJOHEPXOUIFVQTUSFBN QSPEVDFSPGFMFNFOUT
 
 WBMTJOL4JOL<*OU 'VUVSF<*OU>>4JOLGPME<*OU *OU>

     @ @
  6. 'MPX w "QSPDFTTJOHTUBHFXIJDIIBTFYBDUMZPOFJOQVUBOEPVUQVU  XIJDIDPOOFDUTJUTVQTUSFBNBOEEPXOTUSFBNCZUSBOTGPSNJOH UIFEBUBFMFNFOUTqPXJOHUISPVHIJU
 
 WBMqPX'MPX<*OU *OU /PU6TFE>'MPX<*OU>NBQ

    @ 
  7. 3VOOBCMF(SBQI w "'MPXUIBUIBTCPUIFOETlBUUBDIFEzUPB4PVSDFBOE4JOL SFTQFDUJWFMZ BOEJTSFBEZUPCFSVO 
 
 WBMSVOOBCMF(SBQI3VOOBCMF(SBQI<'VUVSF<*OU>>
 TPVSDFWJB qPX

    UP.BU TJOL ,FFQSJHIU 
 WBMSFTVMU'VUVSF<*OU>SVOOBCMF(SBQISVO
  8. #SPBEDBTU 'MPX" CDBTU [JQ 'MPX$ 'MPX# JO PVU JO JO

    JO PVU PVU PVU
  9. val runnable: RunnableGraph[Future[Int]] = RunnableGraph.fromGraph(GraphDSL.create(sink) { implicit b ⇒sink ⇒

    import GraphDSL.Implicits._ val bcast = b.add(Broadcast[Int](3)) val zip = b.add(ZipWith[Int, Int, Int, Int] { (a, b, c) ⇒ a }) source ~> bcast.in bcast.out(0) ~> flowA.async ~> zip.in0 bcast.out(1) ~> flowB.async ~> zip.in1 bcast.out(2) ~> flowC.async ~> zip.in2 zip.out ~> sink ClosedShape })
  10. 4VCTUSFBNT w IUUQTEPDBLLBJPEPDTBLLBDVSSFOUTUSFBNTUSFBN TVCTUSFBNIUNM 'MPX HSPVQ#Z NFSHF 4VCTUSFBNT 'MPX 'MPX

    JO PVU JO JO JO PVU PVU PVU 'MPX PVU JO
  11. val maxSubstreams = 4 val runnableGraph: RunnableGraph[Future[Int]] = source.groupBy(maxSubstreams, _

    % maxSubstreams) .via(flow.async) .mergeSubstreams .toMat(sink)(Keep.right)
  12. "MQBLLB w "MQBLLBJTB3FBDUJWF&OUFSQSJTF*OUFHSBUJPOMJCSBSZGPS+BWBBOE 4DBMB CBTFEPO3FBDUJWF4USFBNTBOE"LLB
 
 IUUQTHJUIVCDPNBLLBBMQBLLB w 4VQQPSUFE
 "84

    ($1 "[VSFBOENPSF
  13. #FTU1SBDUJDFT w "WPJE#MPDLJOH
 
 "CMPDLJOHQSPDFTTUPCFEFMFHBUFEUPB'VUVSFVTJOHBOPUIFS UISFBEQPPMEJ⒎FSFOUGSPNEFGBVMUEJTQBUDIFSUIFSFJTCMPDLJOH QSPDFTTJOHBU4PVSDF 4JOL 'MPXBOEPUIFST EFBEMPDLPDDVST