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

Play and Reactive Streams #play_ja

Play and Reactive Streams #play_ja

In Play meetup 2 (2015/07/05) by @okapies
https://playframeworkja.doorkeeper.jp/events/27023

※ Reactive Streams 入門 (https://speakerdeck.com/okapies/reactive-streams-ru-men-number-jjug) の補足スライドです。

Yuta Okamoto

July 05, 2015
Tweet

More Decks by Yuta Okamoto

Other Decks in Programming

Transcript

  1. Play and
    Reactive Streams
    in 3 minutes
    Yuta Okamoto (@okapies)

    2015/07/05

    View full-size slide

  2. ஫ҙॻ͖
    • ຊεϥΠυ͸ɺ6/24 ͷ JJUG Night Seminar
    Ͱൃදͨ͠ ”Reactive Streams ೖ໳” ͷิ଍ࢿ
    ྉͰ͢ɻ
    • ݩࢿྉ΁ͷϦϯΫ͸ˣͷઆ໌ཝʹॻ͍ͯ͋Δ
    ͷͰɺ͝ڵຯͷ͋Δํ͸ͥͻ͝ࢀর͍ͩ͘͞ɻ

    View full-size slide

  3. ֓ཁ
    !
    !
    !
    !
    ͷؔ܎Λ̏෼Ͱઆ໌͢Δɻ
    Reactive Streams

    View full-size slide

  4. Experimental in Play 2.4
    https://www.playframework.com/documentation/2.4.x/Highlights24
    Iteratee Λ Reactive

    Streams ʹม׵Ͱ͖Δ

    View full-size slide

  5. ҠߦͷऔΓ૊Έ: Reactive Netty
    https://github.com/playframework/playframework/issues/4727
    Ҡߦ͸ஈ֊తʹ࣮ࢪ

    View full-size slide

  6. ࣍ʹى͖Δ͜ͱ (2.5 Ҏ߱)
    1. Netty backend → Akka HTTP backend
    2. Iteratee → Accumulator with Akka Streams

    View full-size slide

  7. Accumulator
    final class Accumulator[-E, +A](sink: Sink[E, Future[A]]) {
    def map[B](f: A => B)
    (implicit executor: ExecutionContext): Accumulator[E, B]
    def recoverWith[B >: A](pf: PartialFunction[Throwable, Future[B]])
    (implicit executor: ExecutionContext): Accumulator[E, B]
    !
    def run(source: Source[E, _])
    (implicit materializer: Materializer): Future[A] =

    source.toMat(sink)(Keep.right).run()
    }
    E ܕͷετϦʔϜ (ෳ਺஋) Λ

    Future[A] (୯Ұ஋) ʹ۩ݱԽ͢Δ
    • Akka Streams (ͷ Sink) ͷബ͍ϥούʔ
    • ཁૉΛྦྷੵ (accumulate) ݁͠ՌΛ Future ʹม׵
    play-streams: play.api.libs.streams.Accumulator

    View full-size slide

  8. Play ͕ Akka ϕʔεͷ FW ʹม਎
    http://www.slideshare.net/Typesafe_Inc/reactive-streams-100-and-why-you-should-care-webinar/39

    View full-size slide

  9. ͢΂͕ͯ Stream ʹͳΔ
    ( ʈωʈ)

    ⊃⊂
    ͜ΕΛ…
    http://www.slideshare.net/rolandkuhn/akka-streams-and-http
    Spary (Akka HTTP ͷલ਎)

    ͷ໰୊఺

    View full-size slide

  10. ͢΂͕ͯ Stream ʹͳΔ
    ( ʈωʈ)

    ⊃ ⊂
    ͜͏͡Ό
    http://www.slideshare.net/rolandkuhn/akka-streams-and-http
    ڊେϑΝΠϧ΍ chunkɺ

    WebSocket ౳Λ౷Ұతʹ

    ѻ͑ΔΑ͏ʹͳΔ

    View full-size slide

  11. ͢΂͕ͯ Akka ʹͳΔ
    http://tech.iheart.com/post/121599571574/why-we-picked-akka-cluster-as-our-microservice
    ͜͜΋ ʹͳΔʁ

    View full-size slide

  12. ඇಉظετϦʔϜॲཧͷ՝୊
    • ϑϩʔ੍ޚʹࣦഊ͢Δͱ buffer ͕ overflow
    ͠ɺύΠϓϥΠϯ͕Ϋϥογϡͯ͠ࢮ͵

    >
    Publisher Subscriber

    View full-size slide

  13. Reactive Streams
    • ඇಉظετϦʔϜॲཧʹ back-pressure ػߏΛ
    Ճ͑ͯࣗಈతͳϑϩʔ੍ޚΛ࣮ݱ͢ΔΞΠσΞ
    • ͜ͷΞΠσΞΛ࣮૷ͨ͠ͷ͕ Reactive Streams
    !
    To be continued…

    View full-size slide

  14. ࢀߟࢿྉ
    • “Play 3 Implementation Plan” https://docs.google.com/document/
    d/1OejviUX5TDlRVeKg1JD9L4qh2Tn21giItmyxRXCydN0/
    edit#heading=h.l3a9tmzfgjwy
    • “Play 2.4͕ґଘੑ஫ೖΛ࠾༻ɼJava 8ʹҠߦ" http://
    www.infoq.com/jp/news/2015/06/play-24-dependency-injection
    • “Reactive Streams and Play 3.0” http://jroper.github.io/play3-
    streams/
    • “Play, Akka streams, and reactive streams” https://
    groups.google.com/forum/#!topic/play-framework-dev/
    tiHAe23PryQ

    View full-size slide