使用.Net进行Oracle高级排队
有人知道如何使用PL / SSQL和ODP.NET从C#实现Oracle Advance Queue?
以下是用于排队邮件的代码示例: private void main(string[] args) { string _connstring = "Data Source=host/DB;User Id=USER;Password=PASSWORD1;"; OracleConnection _connObj = new OracleConnection(_connstring); // Create a new queue object OracleAQQueue _queueObj = new OracleAQQueue("UDT_NAME",_connObj); _connObj.Open(); OracleTransaction _txn = _connObj.BeginTransaction(); // Set the payload type to your UDT _queueObj.MessageType = OracleAQMessageType.Udt; _queueObj.UdtTypeName = "UDT_NAME"; // Create a new message object OracleAQMessage _msg = new OracleAQMessage(); // Create an instance of JobClass and pass it in as the payload for the // message UDT_CUSTOM_CLASS _custClass = new UDT_CUSTOM_CLASS(); // Load up all of the properties of custClass custClass.CustString = "Custom String"; custClass.CustInt = 5; _msg.Payload = custClass; // Enqueue the message _queueObj.EnqueueOptions.Visibility = OracleAQVisibilityMode.OnCommit; _queueObj.Enqueue(_msg); _txn.Commit(); _queueObj.Dispose(); _connObj.Close(); _connObj.Dispose(); _connObj = null; } 这是一个类似的出列过程: private void main(string[] args) { string _connstring = "Data Source=host/DB;User Id=USER;Password=PASSWORD1;"; OracleConnection _connObj = new OracleConnection(_connstring); // Create a new queue object OracleAQQueue _queueObj = new OracleAQQueue("UDT_NAME",_connObj); // Set the payload type to your UDT _queueObj.MessageType = OracleAQMessageType.Udt; _queueObj.UdtTypeName = "UDT_NAME"; _connObj.Open(); OracleTransaction _txn = _connObj.BeginTransaction(); // Dequeue the message. _queueObj.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit; _queueObj.DequeueOptions.Wait = 10; OracleAQMessage _deqMsg = _queueObj.Dequeue(); UDT_CUSTOM_CLASS data = (UDT_CUSTOM_CLASS)_deqMsg.Payload; // At this point,you have the data and can do whatever you need to do with it _txn.Commit(); _queueObj.Dispose(); _connObj.Close(); _connObj.Dispose(); _connObj = null; } 这是一个“简单”的例子.我从Ed Zehoo的Pro ODP.NET for Oracle Database 11g中删除了大部分内容.这是一本很好的书,我强烈建议它帮助你更好地理解OPD.NET所有东西的来龙去脉.您可以在这里购买电子书:http://apress.com/book/view/9781430228202.如果您输入优惠券代码MACWORLDOC,您可以以21.00美元的价格购买电子书.该优惠仅适用于受密码保护的PDF格式的电子书.我希望这有帮助! (编辑:孝感站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |