Without the pub (fanout), it complains that a publisher can't handle more than one subscribers.
On Sunday, October 4, 2015 at 2:00:47 PM UTC-7, √ wrote: > > Why `pub` at all? > > a ~> c should be enough, and then you don't need close() at all, > > `src to partial` should be all you need. (Source + Sink) > > On Sun, Oct 4, 2015 at 10:29 PM, Abhijit Sarkar <[email protected] > <javascript:>> wrote: > >> Thank you, that's exactly what I'd come up with (feels good to know that >> I'm starting to get it :) ). So now I've a Source, a publisher and a >> partial. I'm trying to hook them up as follows but it doesn't compile. >> >> What I'd like to do is to attach the publisher with the partial and then >> hand the whole thing to the source. I've not been able to find a way to do >> that. Basically my idea is to say that "you've a source, I'll give you a >> SinkShape, go run it." Instead, now the class with the source is having to >> construct the publisher, and as I said, that even doesn't compile. >> >> val pub = Sink.fanoutPublisher[Tweet](1, 1) >> >> val src = Source.single(httpRequest).via(flow) >> >> FlowGraph.closed() { implicit builder => >> >> import FlowGraph.Implicits._ >> >> val a = builder.add(src) >> >> val b = builder.add(pub) >> >> val c = builder.add(partial) >> >> a ~> pub ~> c // compiler isn't happy here! >> } >> >> >> >> On Sunday, October 4, 2015 at 1:14:13 PM UTC-7, √ wrote: >>> >>> val partial = FlowGraph.partial() { implicit builder => >>> import FlowGraph.Implicits._ >>> val broadcast = builder.add(Broadcast[HttpResponse](2)) >>> >>> broadcast ~> goodTweets >>> broadcast ~> badTweets >>> >>> SinkShape(broadcast.in) >>> }.named("partial") >>> >>> On Sun, Oct 4, 2015 at 8:30 PM, Abhijit Sarkar <[email protected]> >>> wrote: >>> >>>> I'm afraid it doesn't help much without code example. I've only one >>>> inlet but I'm also not sure how to hook up the fanout publisher with the 2 >>>> sinks. Based on the above code, can you show me what you're suggesting? >>>> >>>> On Sunday, October 4, 2015 at 3:59:33 AM UTC-7, √ wrote: >>>>> >>>>> Hi! >>>>> >>>>> Since what you want only has one inlet, that is what a Sink is, which >>>>> means you should use SinkShape iso FlowShape. >>>>> Does that help? >>>>> >>>>> On Sun, Oct 4, 2015 at 12:03 PM, Abhijit Sarkar <[email protected]> >>>>> wrote: >>>>> >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Cheers, >>>>> √ >>>>> >>>> -- >>>> >>>>>>>>>> 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. >>>> >>> >>> >>> >>> -- >>> Cheers, >>> √ >>> >> -- >> >>>>>>>>>> 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] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at http://groups.google.com/group/akka-user. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Cheers, > √ > -- >>>>>>>>>> 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.
