Implementing transactional messaging for C++ clients

To create a transactional manager

  1. Initialize QAnywhere.

    This step is the same as in non-transactional messaging.

    #include <qa.hpp>
    QAManagerFactory *   factory;
    
    factory = QAnywhereFactory_init();
    if( factory == NULL ) {
        // Fatal error.
    }
  2. Create a transactional manager.

    QATransactionalManager *  mgr;
    mgr = factory->createQATransactionalManager( NULL );
    if( mgr == NULL ) {
        // Fatal error.
    }

    As with non-transactional managers, you can specify a properties file to customize QAnywhere behavior. In this example, no properties file is used.

  3. Initialize the manager.

    if( !mgr->open() ) {
       // Display message using mgr->getLastErrorMsg().
    }

You are now ready to send messages. The following procedure sends two messages in a single transaction.

To send multiple messages in a single transaction

  1. Initialize message objects.

    QATextMessage *  msg_1;
    QATextMessage *  msg_2;
  2. Send the messages.

    The following code sends two messages in a single transaction:

    msg_1 = mgr->createTextMessage();
    if( msg_1 != NULL ) {
      msg_2 = mgr->createTextMessage();
      if( msg_2 != NULL ) {
        if( !mgr->putMessage( "jms_1\\queue_name", msg_1 ) ) {
          // Display message using mgr->getLastErrorMsg().
        } else {
          if( !mgr->putMessage( "jms_1\\queue_name", msg_2 ) ) {
            // Display message using mgr->getLastErrorMsg().
          } else {
            mgr->commit();
          }
        }
        mgr->deleteMessage( msg_2 );
      }
      mgr->deleteMessage( msg_1 );
    }

    The commit method commits the current transaction and begins a new transaction. This method commits all putMessage() method and getMessage() method invocations.

    Note

    The first transaction begins with the call to open method.

See also