-
Notifications
You must be signed in to change notification settings - Fork 8
/
Subscriber.scala
36 lines (30 loc) · 984 Bytes
/
Subscriber.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package stream
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Sink, Source}
import org.reactivestreams.Subscriber
/**
* Created by pabloperezgarcia on 26/01/2017.
*
* create Reactive Streams Subscriber:
* We create the source as subscriber and sink to get the lazy subscriber
* Once that we create the Source with value and we set the subscriber with "to" we start
* using the pipeline
*/
object Subscriber extends App {
implicit val context = ActorSystem()
implicit val materializer = ActorMaterializer()
runSubscriber()
def runSubscriber() {
Source.single("Akka subscription!")
.to(Sink.fromSubscriber(createSubscriber()))
.run()
}
private def createSubscriber():Subscriber[String] = {
val source = Source.asSubscriber[String]
.map(value => value.toUpperCase)
.filter(value => !value.isEmpty)
val sink = Sink.foreach(Console.println)
source to sink run()
}
}