I do it just via ActorPublisher, the "scroll" method is basically 
asynchronously loading elasticsearch records (classic cursor thingy). It's 
a combination of request demand and asynchronous source of events :  

  def receive: Receive = {
    case Request(n) if totalDemand > 0 && n > 0 && isActive =>
      def pushRecursively(n: Long = Math.min(n, totalDemand), scrollId: String 
= lastScrollId): Future[Unit] = {
        
        scroll(scrollId) flatMap {
          case (sid, recs) if recs.isEmpty => // empty hits means end of 
scanning/scrolling
            onComplete()
            context.stop(self)
            Future.successful(())
          case (sid, recs) =>
            lastScrollId = sid
            val contexts = recs.map {
              case (recId, rec) => EsResource :: Map.empty[String, String] :: 
recId :: rec :: HNil
            }
            onNext(contexts)
            if (n > 1)
              pushRecursively(n-1, sid)
            else
              Future.successful(())
        }
      }

      pushRecursively() onComplete {
        case Failure(ex) =>
          onError(ex)
          context.stop(self)
        case s =>
      }

    case Cancel =>
      context.stop(self)
  }
}

-- 
>>>>>>>>>>      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.

Reply via email to