微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用.Net进行Oracle高级排队

有人知道如何使用PL / Ssql和ODP.NET从C#实现Oracle Advance Queue?
我在C#或VB.NET中找不到具有具体示例的单个示例或资源.
理想情况下,我想了解一些关于如何使用简单类型(XMl / string)排队和出列消息的示例.
我无法帮助您掌握最佳实践,但我可以帮助您使用UDT队列.在处理队列之前,需要从数据库生成自定义类型到C#项目中.假设您安装了Visual Studio和ODP.NET,您只需通过Server Explorer连接到数据库,找到您的UDT,右键单击并选择“Generate Custom Class …”这些类直接映射到您的UDT并使用存储出列信息.

以下是用于排队邮件代码示例:

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格式的电子书.我希望这有帮助!

原文地址:https://www.jb51.cc/oracle/205157.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐