3

I can get enumerator from mongodb, using reactivemongo like,

val enumerator = collection.find(rangeQuery)
       .cursor[State]
       .enumerate()

How to stream from this enumerator, using akka-http and akka-stream ?

I have converted the enumerator to publisher using, play streams experimental library,

Streams.enumeratorToPublisher(enumerator)

and stream from, akka-http like,

complete {

Source(publisher).map { a => /*Thread.sleep(100);*/ChunkStreamPart(a.asJson) }
HttpResponse(entity = HttpEntity.Chunked(MediaTypes.`application/json`, source))
}

But, the stream does not ending, the client is still waiting for the data. Is there any issue while creating enumerator ?. Or the issue in converting the Enumerator to publisher ?

I have already posted the question in reactivemongo google user group and play user group https://groups.google.com/forum/#!topic/reactivemongo/uObGXFQFH0Y

S.Karthik
  • 1,389
  • 9
  • 21
  • I have to append.andThen(Enumerator.eof) , as per http://stackoverflow.com/questions/12603414/why-am-i-failing-to-combine-enumerators-in-simpleresult-body – S.Karthik May 06 '15 at 04:20

0 Answers0