-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-- reactive-streams from/to akka / fs2 as an idea to work with Elasti…
…c Search
- Loading branch information
Showing
3 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package fs2x | ||
|
||
import cats.effect.Async | ||
import fs2.interop.reactivestreams._ | ||
import org.reactivestreams.Publisher | ||
import org.reactivestreams.Subscriber | ||
|
||
/** ReactivePlayground | ||
* | ||
* - consuming from org.reactivestreams.Publisher[A] | ||
* to fs2.Stream[F, A] | ||
* | ||
* - publishing to org.reactivestreams.Publisher[A] | ||
* via fs2Stream.subscribe(elasticSearchSubscriber) | ||
*/ | ||
class Fs2ReactivePlayground[F[_]: Async, A] { | ||
|
||
/** having any library providing source as a [[org.reactivestreams.Publisher]] */ | ||
val elasticSearchPublisher: Publisher[A] = ??? | ||
|
||
/** we can easily convert it to fs2Stream */ | ||
val fs2Stream: fs2.Stream[F, A] = fromPublisher[F, A](elasticSearchPublisher, 1000) | ||
|
||
/** having any library providing source as a [[org.reactivestreams.Subscriber]] */ | ||
val elasticSearchSubscriber: Subscriber[A] = ??? | ||
|
||
/** we can sink top it */ | ||
val r: F[Unit] = fs2Stream.subscribe(elasticSearchSubscriber) | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
typesafe/src/main/scala/streaming/AkkaStreamsReactivePlayground.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package streaming | ||
|
||
import akka.NotUsed | ||
import akka.stream.Materializer | ||
import akka.stream.scaladsl.Sink | ||
import akka.stream.scaladsl.Source | ||
import org.reactivestreams.Publisher | ||
import org.reactivestreams.Subscriber | ||
|
||
/** ReactivePlayground | ||
* | ||
* - consuming from org.reactivestreams.Publisher[A] | ||
* to Akka Source | ||
* | ||
* - publishing to org.reactivestreams.Publisher[A] | ||
* Akka Sink implementation | ||
*/ | ||
class AkkaStreamsReactivePlayground[A] { | ||
|
||
implicit val materializer: Materializer = ??? | ||
|
||
/** having any library providing source as a [[org.reactivestreams.Publisher]] */ | ||
val elasticSearchPublisher: Publisher[A] = ??? | ||
|
||
/** we can easily convert it to Akka Stream */ | ||
val akkaStream: Source[A, NotUsed] = Source.fromPublisher(elasticSearchPublisher) | ||
|
||
/** having any library providing source as a [[org.reactivestreams.Subscriber]] */ | ||
val elasticSearchSubscriber: Subscriber[A] = ??? | ||
|
||
/** we can create a [[akka.stream.scaladsl.Sink]] */ | ||
val sink: Sink[A, NotUsed] = Sink.fromSubscriber(elasticSearchSubscriber) | ||
|
||
val r: NotUsed = akkaStream.to(sink).run | ||
|
||
} |