【发布时间】:2017-12-06 18:50:23
【问题描述】:
我正在使用Alpakka 及其JMS 连接器来从Oracle AQ 中取出数据。我可以按照 this 指南提出以下非常基本的实现。
我的问题是如何使它具有事务性,这样我就可以保证在抛出异常时我的消息不会丢失。
object ConsumerApp extends App {
implicit val system: ActorSystem = ActorSystem("actor-system")
implicit val materializer: ActorMaterializer = ActorMaterializer()
val connectionFactory = AQjmsFactory.getConnectionFactory(getOracleDataSource())
val out = JmsSource.textSource(
JmsSourceSettings(connectionFactory).withQueue("My_Queue")
)
val sink = Sink.foreach { message: String =>
println("in sink: " + message)
throw new Exception("") // !!! MESSAGE IS LOST !!!
}
out.runWith(sink, materializer)
}
如果是PL/SQL,解决办法是这样的:
DECLARE
dequeue_options DBMS_AQ.DEQUEUE_OPTIONS_T;
message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
message_handle RAW (44);
msg SYS.AQ$_JMS_TEXT_MESSAGE;
BEGIN
DBMS_AQ.dequeue (
queue_name => 'My_Queue',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => msg,
msgid => message_handle
);
-- do something with the message
COMMIT;
END;
【问题讨论】:
标签: scala jms akka-stream oracle-aq alpakka