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)
오랫동안 기다렸지 만 인쇄가 계속됩니다.
내 기대는 즉시 나를 위해 행을 읽는 표를 시작합니다.