I would like to build a REST service with Akka HTTP that connect to an existing Sink (with Kafka reactive stream) but I cannot figure out how to chain an HTTP flow to an Akka stream sink...
Should I go for the low level Akka HTTP API that use Flows ?
My requirement is to have:
- backpressure on the complete flow
- 200 response code when all events are acknowledged by kafka sink
- 500 when backpressure is too high ? Is it possible ?
Here is my code current code
// flow to split group of lines into lines
val splitLines = Flow[String].mapConcat(_.split("\n").toList)
// sink to produce kafka records in kafka
val kafkaSink = Flow[String]
.map(new ProducerRecord[Array[Byte], String](topic, _))
.toMat(Producer.plainSink(ProducerSettings(system,new ByteArraySerializer, new StringSerializer)))(Keep.right)
val routes = {
path("ingest") {
post {
logger.info("starting ingestion")
entity(as[GenericEvent]) { eventIngest =>
????
}~
entity(as[GenericEventList]) { eventIngestList =>
????
}
}
}
}
Http(actorSystem).bindAndHandle(routes, config.httpInterface, config.httpPort)