0

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.

phantomastray
  • 449
  • 3
  • 16

1 Answers1

0

Although probably not relevant for phantomastray any more but helpful for others:

A KillSwitch allows the completion of graphs of FlowShape from the outside. It consists of a flow element that can be linked to a graph of FlowShape needing completion control. The KillSwitch trait allows to complete or fail the graph(s). [Source: Akka Docs]

Toaditoad
  • 254
  • 2
  • 12