Created
February 26, 2016 09:19
-
-
Save juanjovazquez/be3c903a3b8a8d39f51a to your computer and use it in GitHub Desktop.
Streaming to Cassandra with Quill and Akka Streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tecsisa.wr | |
import akka.actor.ActorSystem | |
import akka.stream.ActorMaterializer | |
import akka.stream.scaladsl.Source | |
import io.getquill._ | |
import io.getquill.naming._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
object Quill extends App { | |
implicit val system = ActorSystem("quill-poc") | |
implicit val materializer = ActorMaterializer() | |
val db = source(new CassandraAsyncSourceConfig[SnakeCase]("db")) | |
case class WeatherStation( | |
country: String, | |
city: String, | |
stationId: String, | |
entry: Int, | |
value: Int) | |
object WeatherStation { | |
val persist = quote(query[WeatherStation].insert) | |
} | |
Source(1 to 10000).runForeach { index => | |
db.run(WeatherStation.persist)(List(WeatherStation("UK", "London", index.toString, index, index))) | |
} | |
.onComplete { _ => | |
db.close() | |
system.terminate() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment