= slick.basic.DatabaseConfig.forConfig(
"slick.h2") val db=
dbConfig.db case class CountyModel(id: Int, name: String) case classCountyTable(tag: Tag) extends Table[CountyModel](tag,
"COUNTY") { def id= column[Int](
"ID",O.AutoInc,O.PrimaryKey) def name= column[String](
"NAME",O.Length(
64)) def* = (id,name)<>
(CountyModel.tupled,CountyModel.unapply) } val CountyQuery=
TableQuery[CountyTable] def loadTable(filter: String)=
{ // implicit val ec = httpSys.dispatchers.lookup("akka.http.blocking-ops-dispatcher")val qry = CountyQuery.filter {_.name.toUpperCase like s
"%${filter.toUpperCase}%"} val publisher=
db.stream(qry.result) Source.fromPublisher(publisher=
publisher) .withAttributes(ActorAttributes.dispatcher("akka.http.blocking-ops-dispatcher")) } } trait JsonCodec extends Json4sSupport { import org.json4s.DefaultFormats import org.json4s.ext.JodaTimeSerializers implicitval serilizer =
jackson.Serialization implicitval formats = DefaultFormats ++
JodaTimeSerializers.all } object JsConverters extends JsonCodec object ServerStreaming extends App { import JsConverters._ implicitval httpSys = ActorSystem(
"httpSystem") implicitval httpMat =
ActorMaterializer() implicitval httpEC =
httpSys.dispatcher implicitval jsonStreamingSupport =
EntityStreamingSupport.json() .withParallelMarshalling(parallelism=
8, unordered =
false) val (port, host)= (
8011,
"localhost") val route=
get { path("files"/Remaining) { name =>
complete(loadFile(name)) }~
path("tables"/Segment) { t =>
complete(SlickDAO.loadTable(t)) } } def loadFile(path: String)=
{ // implicit val ec = httpSys.dispatchers.lookup("akka.http.blocking-ops-dispatcher")val file = Paths.
get(
"/Users/tiger/"+
path) FileIO.fromPath(file, 256) .withAttributes(ActorAttributes.dispatcher("akka.http.blocking-ops-dispatcher")) .map(_.utf8String) } val bindingFuture=
Http().bindAndHandle(route,host,port) println(s"Server running at $host $port. Press any key to exit ...") scala.io.StdIn.readLine() bindingFuture.flatMap(_.unbind()) .onComplete(_=>
httpSys.terminate()) }来源: http://www.cnblogs.com/tiger-xc/p/7792451.html