Previous Next JavaScript must be enabled to correctly display this content

## Configuring Transaction Event Streaming

Learn to configure streaming transaction events using the Oracle NoSQL Database Streams API.

You can optionally configure subscriptions to stream transaction events using the `setStreamDeliveryMode()` method as follows:

    /* create subscription to stream transaction events for UserTableTxn tables */

    import static oracle.kv.pubsub.NoSQLSubscriptionConfig.StreamDeliveryMode.GROUP_ALL_IN_TRANSACTION;

    ...
    final NoSQLSubscriptionConfig subConfig =
        new NoSQLSubscriptionConfig.Builder("ChkptTable")
        .setSubscribedTables("UserTableTxn")
        .setStreamMode(NoSQLStreamMode.FROM_NOW)
        .setStreamDeliveryMode(GROUP_ALL_IN_TRANSACTION,"UserTableTxn")
        .build();

The `setStreamDeliveryMode()` method expects `StreamDeliveryMode` and table name(s) as arguments.

- The `StreamDeliveryMode` argument takes either GROUP_ALL_IN_TRANSACTION or SINGLE_WRITE_EVENT Enum value. You must supply GROUP_ALL_IN_TRANSACTION to stream transaction events. You provide SINGLE_WRITE_EVENT if you want to configure the subscription stream to split apart a transaction event and deliver discrete write operations for every write that was committed in the transaction. The SINGLE_WRITE_EVENT is considered as the default mode if you don't invoke the `setStreamDeliveryMode()` method.
- The table name(s) argument must include tables that exist in the data store. You must first subscribe the tables using the `setSubscribedTables()` method before invoking the `setStreamDeliveryMode()` method. Otherwise, the subscription will fail with the `SubscriptionFailureException` exception.

Note:

In case of hierarchical tables, you must add the root table to the subscription to stream transaction events. All the child tables in the same hierarchy also stream transaction events. For example, if there are updates to a parent table and a child table in a transaction, the Streams API encapsulates all the committed writes in this transaction as a single transaction event and streams it to the subscriber. If you don't configure transaction event streaming, each committed write to either a parent or a child table is streamed as a single stream event.

You can also configure the subscription to include the following while streaming transaction events.

- Mixed mode streaming where the streams deliver transaction events for one subscribed table and a discrete list of committed write events for another subscribed table. In the following code sample, you configure the subscription to the `UserTable` table to stream a discrete list of committed write events and the `UserTableTxn` table to deliver transaction events.

      /**
       * create subscription to stream UserTable and UserTableTxn tables
       * UserTable table streams discrete list of committed writes
       * UserTableTxn table streams transaction events
       */

      import static oracle.kv.pubsub.NoSQLSubscriptionConfig.StreamDeliveryMode.GROUP_ALL_IN_TRANSACTION;
      ...
      final NoSQLSubscriptionConfig subConfig =
          new NoSQLSubscriptionConfig.Builder("ChkptTable")
          .setSubscribedTables("UserTable", "UserTableTxn")
          .setStreamMode(NoSQLStreamMode.FROM_NOW)
          .setStreamDeliveryMode(GROUP_ALL_IN_TRANSACTION, "UserTableTxn")
          .build();

- Add a new subscribed table to a running subscription and stream its transaction events. Here, you can subscribe to another table and stream its transaction events while you have an existing subscription streaming a list of committed write events for the original table. In the following code sample, you first configure a subscription to stream individual write events for the `UserTable` table and then subscribe table `UserTableTxn` to the same subscription to stream transaction events for that table.

      /* create subscription to stream UserTable */
      final NoSQLSubscriptionConfig subConfig =
          new NoSQLSubscriptionConfig.Builder("ChkptTable")
          .setSubscribedTables("UserTable")
          .setStreamMode(NoSQLStreamMode.FROM_NOW)
          .build();

      /* stream all writes */
          ...

      /* subscribe UserTableTxn table to stream transaction events */
          subscriber.clearChangeResultFlag();
          stream.subscribeTable("UserTableTxn", true);

          ...

  Note:

  Adding a table to the subscription at run time to stream its write operations does not impact existing subscriptions and streaming.