Setting up C++ applications

Before you can send or receive messages using QAnywhere C++ clients, you must complete the following initialization tasks.

To initialize the QAnywhere C++ API

  1. Include the QAnywhere header file.

    #include <qa.hpp>

    qa.hpp defines the QAnywhere classes.

  2. Initialize QAnywhere.

    To do this, initialize a factory for creating QAManager objects.

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

    For more information about QAManagerFactory, see QAManagerFactory class.

  3. Create a QAManager instance.

    You can create a default QAManager object as follows:

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

    See QAManager class.

    Tip

    For maximum concurrency benefits, multi-threaded applications should create a QAManager for each thread. See Multi-threading considerations.

    You can customize a QAManager object programmatically or using a properties file.

  4. Initialize the QAManager object.

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

    The argument to the open method is an acknowledgement mode, which indicates how messages are to be acknowledged. It must be one of IMPLICIT_ACKNOWLEDGEMENT or EXPLICIT_ACKNOWLEDGEMENT. With implicit acknowledgement, messages are acknowledged as soon as they are received by the client. With explicit acknowledgement, you must call one of the acknowledge methods on the QAManager to acknowledge the message.

    For more information about acknowledgement modes, see AcknowledgementMode class.

Note

Instead of creating a QAManager, you can create a QATransactionalManager. See Implementing transactional messaging for C++ clients.

You are now ready to send messages.

See also