Skip to content

Instantly share code, notes, and snippets.

@juanjovazquez
Created February 26, 2016 09:19
Show Gist options
  • Save juanjovazquez/be3c903a3b8a8d39f51a to your computer and use it in GitHub Desktop.
Save juanjovazquez/be3c903a3b8a8d39f51a to your computer and use it in GitHub Desktop.
Streaming to Cassandra with Quill and Akka Streams
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