BeginTransaction Method

Begins a new transaction.

Object Oriented Interface

public function doBeginTransaction($id);

Procedural Interface

ipworksmq_stomp_do_begintransaction($res, $id);

Remarks

This method begins a new transaction using the specified Id, which must be unique. There is no limit to how many transactions may be open at any given time.

A transaction is a group of messages and message acknowledgments which are all processed atomically when the transaction is committed or aborted.

Messages sent in a transaction will not be delivered to clients subscribed to the messages' destinations until the transaction is committed.

Since it is possible for multiple transactions to be open at any given time, the TransactionId property is used to specify which transaction (if any) messages should be sent in. Similarly, message acknowledgments can be sent in a transaction by setting the AckTransactionId configuration setting during the MessageIn event handler.

The OpenTransactions configuration setting can be queried at any time to retrieve a comma-separated list of currently open transactions' Ids.

Basic Transaction Example

// Open a new transaction.
stomp1.BeginTransaction("txn1");
// Set the Transaction property to make sure that messages are sent as part of the transaction.
stomp1.Transaction = "txn1";

stomp1.SendMessage("test/a/b", "Hello, world!");
stomp1.SendMessage("test/a/b", "This is a test.");
stomp1.SendMessage("test/a/b", "Another test!");

// At this point, none of the messages sent above would have been delivered to any clients
// subscribed to the "test/a/b" destination yet, because the transaction is still open.

// If we close and commit the transaction, the server will then deliver the messages to subscribers,
// queue them, or process them in another manner; the behavior is server-dependent.
stomp1.CommitTransaction("txn1");

// Or, the transaction can be aborted, in which case the server will discard the messages
// without delivering them to the subscribers.
//stomp1.AbortTransaction("txn1");

// Reset (or change) the Transaction property after committing or aborting a transaction
// so that future messages are not associated with the previous transaction.
stomp1.Transaction = "";

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks MQ 2020 PHP Edition - Version 20.0 [Build 8155]