2017-09-20 9 views
0
val enableJdbcStreaming: (java.sql.Statement) => Unit = { statement ⇒ 
    if (statement.isWrapperFor(classOf[com.mysql.jdbc.StatementImpl])) { 
     statement.unwrap(classOf[com.mysql.jdbc.StatementImpl]).enableStreamingResults() 
    } 
} 

implicit val actorSystem = ActorSystem() 
implicit val actorMaterializer = ActorMaterializer() 
val config = ConfigFactory.load() 
val db = Database.forConfig("mysql") 
val query = Tables.Foo.map(r => (r.id, r.pid)).result 
val source = Source.fromPublisher[(Long, Option[Long])](db.stream(query.withStatementParameters(statementInit = enableJdbcStreaming))) 
val future = source.runForEach(x => println(x)) 
import actorSystem.distpatcher 
future.onComplete{ _ => 
    db.close() 
    actorSystem.terminate() 
} 
Await.result(future, Duration.Inf) 
Await.result(actorsystem.whenTerminated, Duration.Inf) 

라이브러리 의존성슬릭 3 MySQL의 스트리밍 응용 프로그램은

mysql { 
    profile = "slick.jdbc.MySQLProfile$" 
    dataSourceClass = "slick.jdbc.DatabaseUrlDataSource" 
    properties { 
    driver = "com.mysql.jdbc.Driver" 
    url = "jdbc:mysql://server:3306/db" 
    user = "user" 
    password = "password" 
    } 
    connectionTimeout = 300 
} 

나는이 코드를 실행

"com.lightbend.akka" %% "akka-stream-alpakka-cassandra" % "0.11", 
"com.typesafe.slick" %% "slick" % "3.2.1", 
"com.typesafe.slick" %% "slick-hikaricp" % "3.2.1", 
"mysql" % "mysql-connector-java" % "5.1.44", 
"ch.qos.logback" % "logback-classic" % "1.2.3" 

MySQL의 설정 (데이터를 스트리밍하지 않습니다) ... 달려 있습니다. 콘솔에이 줄을 계속 인쇄합니다.

[info] 19:20:31.647 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:21:01.649 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:21:31.656 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:22:01.661 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:22:31.668 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:23:01.674 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:23:31.680 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:24:01.687 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:24:31.693 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:25:01.699 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:25:31.706 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 
[info] 19:26:01.708 [mysql housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - mysql - Pool stats (total=21, active=1, idle=20, waiting=0) 

오랫동안 기다렸지 만 인쇄가 계속됩니다.

내 기대는 즉시 나를 위해 행을 읽는 표를 시작합니다.

답변

0

나는 스스로 문제를 해결했다. 나는 그래프를 올바르게 작성하지 않고 있다고 생각한다.

RunnableGraph를 사용하여 그래프를 다시 작성했습니다. 이제는 완벽하게 작동합니다.

이전 접근 방식이 작동하지 않은 이유는 흥미로운 일입니다.