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

SQL Anywhere 11.0.1 (中文) » QAnywhere » 编写 QAnywhere 客户端应用程序 » 初始化 QAnywhere API

 

设置 C++ 应用程序

使用 QAnywhere C++ 客户端发送或接收消息之前,必须完成以下初始化任务。

♦  初始化 QAnywhere C++ API
  1. 包括 QAnywhere 头文件。

    #include <qa.hpp>

    qa.hpp 定义 QAnywhere 类。

  2. 初始化 QAnywhere。

    为此,初始化用于创建 QAManager 对象的工厂。

    QAManagerFactory * factory;
    
    factory = QAnywhereFactory_init();
    if( factory == NULL ) {
          // Fatal error.
    }

    有关 QAManagerFactory 的详细信息,请参见QAManagerFactory 类

  3. 创建 QAManager 实例。

    您可以按以下方法创建缺省 QAManager 对象:

    QAManager *  mgr;
    
    // Create a manager
    mgr = factory->createQAManager( NULL );
    if( mgr == NULL ) {
      // fatal error
    }

    请参见QAManager 类

    提示

    为了提供最大并发数,多线程应用程序应为每个线程创建一个 QAManager。请参见多线程注意事项

    可以以编程方式或使用属性文件自定义 QAManager 对象。

  4. 初始化 QAManager 对象。

    qa_bool  rc;
    rc=mgr->open( 
         AcknowledgementMode::IMPLICIT_ACKNOWLEDGEMENT );

    open 方法的参数是确认模式,它指示确认消息的方式。它必须是 IMPLICIT_ACKNOWLEDGEMENTEXPLICIT_ACKNOWLEDGEMENT 两种方式中的某一种。使用隐式确认时,客户端在收到消息时会进行确认。使用显式确认时,必须在 QAManager 上调用一种确认方法对消息进行确认。

    有关确认模式的详细信息,请参见AcknowledgementMode 类

注意

您可以创建 QATransactionalManager 而非 QAManager。请参见为 C++ 客户端实现事务性消息传递

现在,即可发送消息。

另请参见