I'm using Alpakka JMS connector to dequeue items from Oracle AQ, and Slick for database operations, the queue and the tables are on the same schema.
I need to make the dequeue and DB operations transactionally, so if one fails, the other will also fail. Is there a way to achieve this functionality?
What I've come up so far is to have two separate transactions, which is not safe:
val source: Source[Message, NotUsed] = JmsSource(
JmsSourceSettings(connectionFactory)
.withQueue("My_Queue").withBufferSize(10)
.withAcknowledgeMode(AcknowledgeMode.ClientAcknowledge)
)
val sink = Sink.foreach { m: Message =>
val txtMessage = m.asInstanceOf[TextMessage].getText
// commits only for Slick
val dbResult = db.run(
(for{
tableUpdate <- updateTable()
result <- updateAnotherTable()
} yield result).transactionally
)
dbResult.map { _ =>
// commits only for JMS
m.acknowledge()
}
}
source.runWith(sink)