原創(chuàng)|使用教程|編輯:郝浩|2013-04-25 11:06:38.000|閱讀 681 次
概述: 高級隊列(AQ)是內(nèi)置在Oracle服務(wù)器上的一個靈活的信息交流機制,使用這個高級隊列,你可以將來自一個工作站或服務(wù)器的信息發(fā)送到一個或是多個工作站上。dotConnect for Oracle采用類集合來充分的利用這項技術(shù)。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
高級隊列(AQ)是內(nèi)置在Oracle服務(wù)器上的一個靈活的信息交流機制,使用這個高級隊列,你可以將來自一個工作站或服務(wù)器的信息發(fā)送到一個或是多個工作站上。dotConnect for Oracle采用類集合來充分的利用這項技術(shù)。
首先來看一下高級隊列(AQ),主要通過下面的幾部分來具體的了解:
高級隊列提供了數(shù)據(jù)庫集成的消息隊列功能,高級隊列信息可以持久存儲、不同數(shù)據(jù)或是數(shù)據(jù)庫上隊列之間的傳播、使用Oracle網(wǎng)絡(luò)服務(wù)的傳輸、HTTP、SMTP。
由于Oracle高級隊列是在數(shù)據(jù)庫表上實現(xiàn)的,高可用性、可擴展性和可靠性完全適用于隊列的數(shù)據(jù)。這項技術(shù)是由DBMS_AQ 和DBMS_AQADM2個包實現(xiàn),DBMS_AQ包管理隊列的信息,如入隊和出隊,DBMS_AQADM則是負責(zé)管理生命周期以及屬性。
支持標準的數(shù)據(jù)庫功能,如恢復(fù)、重啟、安全性、以及隊列表的導(dǎo)入好和導(dǎo)出,還支持信息管理功能和異步通信功能。
下面是AQ的兩種功能模式:點對點模型和發(fā)布訂閱模型。在第一個中,將會有應(yīng)用程序發(fā)送消息到隊列(稱為enqueuing),以及一個用于退出隊列信息的用戶應(yīng)用程序(稱為dequeuing)。可以有多個用戶應(yīng)用程序,但是任何的一條信息只能夠讀取一次,同時用戶可以瀏覽沒有退出隊列的信息。
在發(fā)布訂閱模型中,有一些入隊和出隊信息的應(yīng)用程序,這些信息可以是針對特定的應(yīng)用程序,或是被目的地所接收,應(yīng)用程序接信息也被稱為代理。
dotConnect for Oracle中有一些類用于提供AQ功能,這些類主要是以下幾種:
OracleQueueMessage對象主要是代表了隊列信息,主要被用于排隊信息的參數(shù),并被出對的方法返回。
OracleQueueMessages包含了系統(tǒng)生成的消息標志符和消息載荷,是char或用戶定義的對象類型。
在這里有一個點到點的消息擴展的示例,方便大家理解:
[C#]
OracleConnection oracleConnection = new OracleConnection( "User Id=system;Password=manager;Server=ora;"); oracleConnection.Open(); OracleQueueTable oracleQueueTable = new OracleQueueTable( "QUEUE_TABLE_MESSAGE", oracleConnection); // Set sort order by priority for the queue. // The messages with higher priority will reach the recipient first. oracleQueueTable.Options.SortOrder = OracleQueueSortOrder.PriorityEnqueueTime; // Specify type of the messages in the queue. //This time each message will be represented by just a string object. //We do so to simplify the unimportant details and concentrate on the advanced features of AQ oracleQueueTable.Options.PayloadTypeName = "RAW"; // The following operations are same as in the previous example. oracleQueueTable.CreateQueueTable(); OracleQueueAdmin oracleQueueAdmin = new OracleQueueAdmin("MESSAGE_QUEUE", "QUEUE_TABLE_MESSAGE", oracleConnection); oracleQueueAdmin.CreateQueue(); oracleQueueAdmin.StartQueue(); OracleQueue oracleEnqueueQueue = new OracleQueue("MESSAGE_QUEUE", oracleConnection); // Create and send the first message. OracleQueueMessage message1 = new OracleQueueMessage(); message1.StringPayload = "First message."; message1.MessageProperties.Priority = 7; oracleEnqueueQueue.Enqueue(message1); // Create and send the second message. This message is assigned a higher priority value. // The message will be consumed first, regardless of the fact that it was sent later. OracleQueueMessage message2 = new OracleQueueMessage(); message2.StringPayload = "Second message with high priority."; message2.MessageProperties.Priority = 1; oracleEnqueueQueue.Enqueue(message2); // Create an object that receives the two messages. OracleQueue oracleDequeueQueue = new OracleQueue("MESSAGE_QUEUE", oracleConnection); oracleDequeueQueue.DequeueOptions.WaitTimeout = 1; // Retrieve the messages in a loop. Once there are two messages received, quit. // (ex.Code == 25228) specifies that the error occured is ORA-25228; it is thrown when the dequeuing timeout expires // or the end of the queue is reached without dequeuing a message. int messageCount = 0; while (messageCount < 2) { try { OracleQueueMessage msg = oracleDequeueQueue.Dequeue(); messageCount++; if (msg != null && msg.StringPayload != null) { Console.WriteLine(msg.StringPayload); } } catch(OracleException ex) { if (ex.Code == 25228) { continue; } else throw ex; } } //Stop and destroy the queue and the queue table oracleQueueAdmin.StopQueue(); oracleQueueAdmin.DropQueue(); oracleQueueTable.DropQueueTable(); oracleConnection.Close();
[Visual Basic]
Dim oracleConnection As New OracleConnection(( "User Id=system;Password=manager;Server=ora;") oracleConnection.Open() Dim oracleQueueTable As New OracleQueueTable("QUEUE_TABLE_MESSAGE", oracleConnection) ' Set sort order by priority for the queue. ' The messages with higher priority will reach the recipient first. oracleQueueTable.Options.SortOrder = OracleQueueSortOrder.PriorityEnqueueTime ' Specify type of the messages in the queue. This time each message will be represented by just a string object. ' We do so to simplify the unimportant oracleQueueTable.Options.PayloadTypeName = "RAW" ' The following operations are same as in the previous example. oracleQueueTable.CreateQueueTable() Dim oracleQueueAdmin As New OracleQueueAdmin("MESSAGE_QUEUE", _ "QUEUE_TABLE_MESSAGE", oracleConnection) oracleQueueAdmin.CreateQueue() oracleQueueAdmin.StartQueue() Dim oracleEnqueueQueue As New OracleQueue("MESSAGE_QUEUE", oracleConnection) ' Create and send the first message. Dim message1 As New OracleQueueMessage message1.StringPayload = "First message." message1.MessageProperties.Priority = 1 oracleEnqueueQueue.Enqueue(message1) ' Create and send the second message. This message is assigned a higher priority value. ' The message will be consumed first, regardless of the fact that it was sent later. Dim message2 As New OracleQueueMessage message2.StringPayload = "Second message with high priority." message2.MessageProperties.Priority = 7 oracleEnqueueQueue.Enqueue(message2) ' Create an object that receives the two messages. Dim oracleDequeueQueue As New OracleQueue("MESSAGE_QUEUE", oracleConnection) oracleDequeueQueue.DequeueOptions.WaitTimeout = 1 ' Retrieve the messages in a loop. Once there are two messages received, quit. ' (ex.Code == 25228) specifies that the error occured is ORA-25228; ' it is thrown when the dequeuing timeout expires or the end of the queue is reached ' without dequeuing a message. Dim messageCount As Integer = 0 Do While (messageCount < 2) Try Dim msg As OracleQueueMessage = oracleDequeueQueue.Dequeue() messageCount += 1 if ((Not msg Is Nothing) AndAlso (Not msg.StringPayload Is Nothing)) Then Console.WriteLine(msg.StringPayload) End If Catch ex As OracleException If (ex.Code = 25228) Then Continue Do Else Throw ex End If End Try Loop oracleQueueAdmin.StopQueue() oracleQueueAdmin.DropQueue() oracleQueueTable.DropQueueTable() oracleConnection.Close()
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件