I'm cutting my teeth on Akka streams, building the quintessential Twitter
streaming client. What I'm trying to do is some processing on the tweet
stream and then based on the result, divide the stream into "good" and
"bad" streams. Both streams are directed to the same ActorPublisher class
instantiated with different names. Following is my code so far but I'm at a
loss connecting all the components. Please help.
val s = Sink.fanoutPublisher[Tweet](1, 1)
val goodSink = Sink.actorSubscriber(TwitterSubscriber.props(
"GoodTwitterSubscriber"))
val badSink = Sink.actorSubscriber(TwitterSubscriber.props(
"BadTwitterSubscriber"))
val allTweets = Flow[HttpResponse].map { _.entity.dataBytes }.flatten(
FlattenStrategy.concat).map {
b => parseTweet(b.utf8String)
}
val afterEpoch = (t: Tweet) => t.createdAt.getYear > 1970
val goodTweets: Sink[HttpResponse, Unit] = allTweets.splitWhen { afterEpoch
}.to(goodSink)
val badTweets: Sink[HttpResponse, Unit] = allTweets.splitWhen { !afterEpoch(
_)}.to(badSink)
// I think this is wrong!
val partial = FlowGraph.partial() { implicit builder =>
import FlowGraph.Implicits._
val broadcast = builder.add(Broadcast[HttpResponse](2))
broadcast ~> goodTweets
broadcast ~> badTweets
// I don't need an outlet, only an inlet, but partial needs an outlet
val outlet = builder.add(Source.empty)
FlowShape(broadcast.in, outlet)
}.named("partial")
In another class:
val httpRequest = this.httpRequest { queryParams(follow, track) }
val flow = this.flow { httpRequest }
val src = Source.single(httpRequest).via(flow)
src.via(partial).to(Sink.ignore)
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.