Skip to main content
Pulsar transactions enables event-streaming applications to consume, process, and produce messages in one atomic operation. That means:
  • Atomic writes across multiple topic partitions
  • Atomic acknowledgments across multiple topic partitions
  • All the operations made within one transaction either all succeed or all fail
  • Consumers are ONLY allowed to read committed messages

Quick start

This section describes how to use the Transaction API to send and receive messages.

Prerequisites

  • Java 1.8 or higher version
  • Pulsar cluster 2.9.1 or higher version

Get the service URL of your StreamNative cluster

To get the service URL(s) of a StreamNative cluster, follow these steps.
  1. Navigate to the Cluster Dashboard page by switching to the cluster workspace.
  2. On the Cluster Dashboard page, click Details tab.
  3. You will see the available service URLs in the Access Points area.
  4. You can click Copy at the end of the row of the service URL that you want to use.

Get the OAuth2 credential file of your service account

To get an OAuth2 credential file of a service account through the StreamNative Console, follow these steps.
  1. On the left navigation pane, click Service Accounts.
  2. In the row of the service account you want to use, in the Key File column, click the Download icon to download the OAuth2 credential file to your local directory. The OAuth2 credential file should be something like this:

Enable Transactions on your StreamNative cluster

  1. Log in to StreamNative Cloud Console.
  2. On the left navigation pane, in the Admin area, click Pulsar Clusters.
  3. Click Edit Cluster.
  4. Select the Advanced tab. In the Features area, enable the Transaction option. Transactions on Cloud

Use Transactions on your application

This example enables you to perform the following operations.
  1. Create a Pulsar client and enable Transactions.
  2. Create three producers to produce messages with a transaction to one input topic (input-topic) and two output topics (output-topic-1 and output-topic-2).
  3. Create three consumers to consume messages with a transaction from one input topic (input-topic) and two output topics (output-topic-1 and output-topic-2).
  4. Commit the transaction after the consumers consume messages successfully.
  • serviceUrl: the broker service URL of your StreamNative cluster.
  • issuerUrl: the URL of your OAuth2 authentication provider. You can get the value from your downloaded OAuth2 credential file.
  • credentialsUrl: the path to your downloaded OAuth2 credential file. The privateKey parameter supports the following pattern formats:
    • file:///path/to/file
    • file:/path/to/file
    • data:application/json;base64,<base64-encoded value>
  • audience: the audience parameter is the Uniform Resource Name (URN), which is a combination of the urn:sn:pulsar, the organization name, and the Pulsar instance name, in this format urn:sn:pulsar:<org_name>:<instance_name>.
You should see the following output:
For a complete example about how to connect to a StreamNative cluster through the Transaction API, see Transaction API examples.