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

SQL Anywhere 11.0.0 » QAnywhere » Creating QAnywhere Applications » Writing QAnywhere client applications » Sending QAnywhere messages » Implementing transactional messaging

 

Implementing transactional messaging for Java clients

To create a transactional manager

  1. Initialize QAnywhere.

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

    import ianywhere.qanywhere.client;
    QAManagerFactory factory = new QAManagerFactory();

    See QAManagerFactory class.

  2. Create a QATransactionalManager object.

    For example, to create a default QATransactionalManager object, invoke createQATransactionalManager with null as its parameter:

    QAManager mgr;
    mgr = factory.createQATransactionalManager( null );

    You can alternatively create a QATransactionalManager object that is customized using a properties file. The properties file is specified in the createQATransactionalManager method:

    mgr = factory.createQATransactionalManager( "qa_mgr.props" );

    where qa_mgr.props is the name of the properties file that resides on the remote device.

  3. Initialize the QAManager object.

    mgr.open();

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();
          }
        }
      }
    }

    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.