Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.1 » QAnywhere » 如何编写 QAnywhere 客户端应用程序 » 发送 QAnywhere 消息 » 事务性消息传递实现

 

为 .NET 客户端实现事务性消息传递

 ♦ 创建事务性管理器
  1. 初始化 QAnywhere。

    这一步骤与在非事务性消息传递中的步骤相同。

    using iAnywhere.QAnywhere.Client;
  2. 创建 QATransactionalManager 对象。

    例如,要创建缺省的 QATransactionalManager 对象,可调用 CreateQATransactionalManager:

    QATransactionalManager mgr = fact.CreateQATransactionalManager();  // no argument

    也可以创建使用属性文件自定义的 QATransactionalManager 对象。属性文件在 CreateQATransactionalManager 方法中指定:

    QAManagerFactory fact = QAManagerFactory.Instance( "qa_mgr.props" );

    其中,qa_mgr.props 是远程设备上属性文件的名称。

  3. 初始化 QAManager 对象。

    mgr.Open();

现在,即可发送消息。以下过程在一个事务中发送两条消息。

 ♦ 在一个事务中发送多条消息
  1. 初始化消息对象。

    QATextMessage msg_1;
    QATextMessage msg_2;
  2. 发送消息。

    以下代码在一个事务中发送两条消息:

         msg_1 = mgr.CreateTextMessage();
         msg_2 = mgr.CreateTextMessage();
         mgr.PutMessage( "jms_1\\queue_name", msg_1 );
         mgr.PutMessage( "jms_1\\queue_name", msg_2 );
         mgr.Commit();

    Commit 方法可提交当前事务并开始一个新事务。此方法提交全部 PutMessage() 方法和 GetMessage() 方法调用。

    注意

    第一个事务以对 open 方法的调用开始。

 另请参见