demonstrateTransactions function

Future<void> demonstrateTransactions(
  1. StompClient client
)

Implementation

Future<void> demonstrateTransactions(StompClient client) async {

  // Begin a transaction
  final transaction = await client.beginTransaction();

  try {
    // Send multiple messages within the transaction
    await client.send(
      destination: '/queue/orders',
      body: 'Order #1: 10 widgets',
      transactionId: transaction.id,
    );

    await client.send(
      destination: '/queue/orders',
      body: 'Order #2: 5 gadgets',
      transactionId: transaction.id,
    );


    // Commit the transaction
    await client.commitTransaction(transactionId: transaction.id);

  } catch (e) {
    // Abort the transaction on error
    await client.abortTransaction(transactionId: transaction.id);
    rethrow;
  }
}