Suppose I have following simple graph.
class KafkaSource[A](kI: KafkaIterator) extends GraphStage[SourceShape[A]] {
val out = Outlet[A]("KafkaSource.out")
override val shape = SourceShape.of(out)
override def createLogic(attr: Attributes): GraphStageLogic =
new GraphStageLogic(shape) {
setHandler(out, new OutHandler {
override def onPull(): Unit = {
push(out, kI.next)
}
})
}
}
val g = GraphDSL.create(){ implicit b =>
val source = b.add(new KafkaSource[Message](itr))
val sink = b.add(Sink.foreach[Message](println))
source ~> sink
ClosedShape
}
we're running it as
RunnableGraph.fromGraph(g).run()
I wish to signal the kafkaSource to stop(or artificially complete) instead of pushing the next available element, so that connected stages downstream also stop.
how do I accomplish that ?
The scenario being, we have millions of messages in kafka & we would like to stop processing messages everyday at 9pm (for instance) and assuming we're stopping our running applications with a clean shutdown.