Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka-http streaming using Slick 3.0 Databasepublisher

I am using slick 3.0 and have a databasepublisher object as

def getAsStream = db.stream[Entity](tblquery.result)

I am using akka-http for rest layer as follows,

val route = 
path("stream"){
 get {
    complete { // how to stream from here  }
  }
}

How can I use this databasepublisher object, to transform(json) and stream each row to the client. Please help.

like image 493
S.Karthik Avatar asked Apr 15 '15 16:04

S.Karthik


1 Answers

I finally doing something like this, do not know whether its right way,

 complete {
       val source = Source(repository.getAsStream).map(a => ChunkStreamPart(a.asJson))
       HttpResponse(entity = HttpEntity.Chunked(MediaTypes.`application/json`, source))
         }
like image 55
S.Karthik Avatar answered Nov 09 '22 12:11

S.Karthik