使用.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名目标电子书.我但愿这有辅佐! (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |

