我正在整合Flickr应用程序,我希望获得完整的用户信息。
我正在使用import akka.NotUsed
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, FlowShape}
import akka.stream.scaladsl.{Balance, Flow, GraphDSL, Merge, Sink, Source}
object q40545440 {
def main(args: Array[String]): Unit = {
implicit val sys = ActorSystem()
implicit val mat = ActorMaterializer()
case class TestObject(x: String)
// Flow that's being used
def processingStage(name: String): Flow[TestObject, TestObject, NotUsed] =
Flow[TestObject].map { s ⇒
println(name + " started processing " + s + " on thread " + Thread.currentThread().getName)
Thread.sleep(1000) // Simulate long processing *don't sleep in your real code!*
println(name + " finished processing " + s)
s
}
// Stream to a parallel processing pool of workers
// See http://doc.akka.io/docs/akka/2.4/scala/stream/stream-cookbook.html#Balancing_jobs_to_a_fixed_pool_of_workers
def balancer[In, Out](worker: Flow[In, Out, Any], workerCount: Int): Flow[In, Out, NotUsed] = {
import GraphDSL.Implicits._
Flow.fromGraph(GraphDSL.create() { implicit b =>
val balancer = b.add(Balance[In](workerCount, waitForAllDownstreams = true))
val merge = b.add(Merge[Out](workerCount))
for (_ <- 1 to workerCount) {
// for each worker, add an edge from the balancer to the worker, then wire
// it to the merge element
balancer ~> worker.async ~> merge
}
FlowShape(balancer.in, merge.out)
})
}
def startStream(list: List[TestObject]) = {
val completion = Source[TestObject](list)
.via(balancer(processingStage("A"), 5))
.via(balancer(processingStage("B"), 5))
.runWith(Sink.foreach(s ⇒ println("Got output " + s)))
}
startStream(List(
TestObject("a"),
TestObject("b"),
TestObject("c"),
TestObject("d")))
sys.terminate()
}
}
方法,但我没有得到关注者并跟踪特定用户的列表。
任何人都可以建议一种方法吗?