2017-07-25 37 views
1

我们试图在.NET 4.7中使用Oracle AQ为我们的应用程序构建排队系统。Oracle高级队列 - 离队提交/回滚

基本上,我们的问题是我们想要将包含其他指令的上层事务中的出队过程包装起来,并且能够在执行queue.Dequeue()指令后“手动”提交或回滚。

到目前为止,这仅适用于入列:

using (var tr = con.BeginTransaction()) 
{ 
    try 
    { 
     enqMsg.SenderId = new OracleAQAgent("SUBSCRIBER1"); 
     enqMsg.Payload = new OracleXmlType(con, new XDocument(
      new XElement("workflowexecution", 
       new XElement("id", i), 
       new XElement("workflowname", Guid.NewGuid().ToString().Substring(0, 8)), 
       new XElement("requestsource", Guid.NewGuid().ToString().Substring(0, 6)))).ToString()); 

     queue.Enqueue(enqMsg); 

     //Other instructions here... 

     tr.Commit(); 
    } 
    catch (Exception) 
    { 
     tr.Rollback(); 
    } 
} 

用同样的方法,我们正在努力进行

queue.Dequeue() 

,然后提交或回滚,但似乎并不上班。这里的出队片段:

//Queue declaration 
queue = new OracleAQQueue("QueueName", con) 
{ 
    MessageType = OracleAQMessageType.Xml, 
    NotificationConsumers = new[] { "SUBSCRIBER1" }, 
    DequeueOptions = 
    { 
     ConsumerName = "SUBSCRIBER1", 
     DequeueMode = OracleAQDequeueMode.Remove, 
     Visibility = OracleAQVisibilityMode.OnCommit, 
    } 
}; 

//Dequeueing process 
using (var tr = con.BeginTransaction()) 
{ 
    try 
    { 
     OracleAQMessage _deqMsg = queue.Dequeue(); 

     //read the payload 
     var reader = _deqMsg?.Payload as XmlTextReader; 

     if (reader != null) 
     { 
      reader.Read(); 
      Console.WriteLine("Received message from queue: " + reader.ReadOuterXml()); 
     }      

     //Further instructions... 
     tr.Commit(); 
    } 
    catch (Exception ex) 
    { 
     tr.Rollback(); 
    } 
} 

出队总是提交事务,并从队列中永久删除邮件,执行的,而不是提交回滚时也是如此。任何人都知道为什么它不与Dequeueing合作?

+0

定义“不工作”。另外,请考虑不使用异常处理程序,只是在没有检查机会的情况下丢弃任何错误。 –

+0

通过不工作,我的意思是即使在执行回滚之后,该队列也会从队列中永久删除。 –

回答

0

设置事务后离队的选择已经开始或将其传递给queue.Dequeue()