I have a scenario in which I am starting multiple jmsSource (for different queues) using alpakka. I also need to detach the queues at any point in time. So I have added KillSwitch to the jms akka streams as below :-
trait MessageListener {
lazy val jmsPipeline = jmsSource
.map { x => log.info(s"Received message ${x} from ${queue}"); x }
.viaMat(KillSwitches.single)(Keep.right)
.toMat(Sink.foreach { x => pipelineActorRef ! PreProcessorMessage(x) })
(Keep.both)
.run()
def start(): Unit = {
log.info("Invoking listener : {}", queue)
jmsPipeline
log.info("listener : {} started", queue)
}
def stop():Unit = jmsPipeline._1.shutdown()
def queue: String
}
object ListenerA extends MessageListener {
override def queue: String = "Queue_A"
}
object ListenerB extends MessageListener {
override def queue: String = "Queue_B"
}
.. and so on.
After I start up the application, all the queues are connected and works fine. But when I try to detach the queue using the stop method, not all the queues gets disconnected and the behaviour is random. I also checked that the killSwitch is different for all the listeners.
Could someone please tell me what's getting wrong here?