Beginning a Transaction
To begin a transaction, first instantiate a new BrokerTransactionalClient object, then call the transactional client's beginTransaction method.
A unique Broker transaction ID that is specific to this newly opened transaction will be generated and returned as part of the new transaction object. This ID is unique to the specific Broker.
Note that this method can be null or can have an external transaction ID.
//unique Broker transaction ID
long tid;
//Create Transactional Client:
try {
BrokerTransactionalClient pub =
BrokerTransactionalClient.newOrReconnect
(broker_host, broker_name,pubid, client_group_p, "TxTest-Pub", null);
} catch (BrokerException ex)
{
System.out.println ("Failed to create pub client\n" + ex);
System.exit(1);
}
//beginTransaction:
// Start a transaction to publish events
try {
tid = pub.beginTransaction(null);
} catch (BrokerException ex) {
System.out.println ("Error on starting transaction " +ex);
return;
}
. . .