Using NoSQLSubscriptionConfig

You configure your subscription by building an oracle.kv.pubsub.NoSQLSubscriptionConfig object. You then provide this object to your NoSQLSubscriber implementation, and also implement NoSQLSubscriber.getSubscriptionConfig() to return this object when it is called. When you construct the publisher, you will provide it with your NoSQLSubscriber implementation, and the publisher will then call NoSQLSubscriber.getSubscriptionConfig() in order to understand how to create the subscription. See Implementing Subscribers and Using a Streams Publisher.

To build your NoSQLSubscriptionConfig object, you use NoSQLSubscriptionConfig.Builder as follows:

final NoSQLSubscriptionConfig subConfig =
	new NoSQLSubscriptionConfig.Builder("ChkptTable")
    .setSubscribedTables("UserTable")
    .setStreamMode(NoSQLStreamMode.FROM_NOW)
    .build(); 

This configuration causes the subscription to:

  • Use the checkpoint table called ChkptTable. For more information about checkpoint table, see Using Checkpoints. Be aware that the table name used here is chosen by you, and should be unique to your subscription. If you are using multiple subscriptions, then each subscription should use a unique name for the checkpoint table. This table is created automatically.

    If you are using a secure store, you need read/write access to the checkpoint table. If a checkpoint table does not exist, you also need the CREATE TABLE privilege. For information about:
  • Subscribe to all write activity performed on the user table called UserTable. Subscriptions can be created for user-defined tables; updates to system tables would not be streamed. You can use this to subscribe to multiple tables:

    new NoSQLSubscriptionConfig.Builder("ChkptTable")
     .setSubscribedTables("UserTable", "PriceTable", "InventoryTable") .... 

    If you do not call setSubscribedTables(), then the subscription will subscribe to all tables in the store. If a subscription is for every table in the store, and a new a table is created after subscription is established (using the DDL CREATE TABLE operation), the stream will include all put events for every row created in the new table.

  • Set the stream mode to NoSQLStreamMode.FROM_NOW. The stream mode indicates from where in the stream the Publisher will start retrieving events. For more information, see NoSQLStreamMode.

Once you have created your subscription configuration, you provide it to your NoSQLSubscriber implementation, which then must make it available via the NoSQLSubscriber.getSubscriptionConfig() method:

class mySubscriber implements NoSQLSubscriber {

    ...

    private final NoSQLSubscriptionConfig config;

    ...

    // Generally the constructor will require more than just
    // the subscription configuration. The point here is that you
    // must somehow provide the configuration object to
    // your subscriber implemention because that is how
    // your publisher will get it.
    mySubscriber(NoSQLSubscriptionConfig config, ....) {

        ...

        this.config = config;

        ...
    }

    @Override
    public NoSQLSubscriptionConfig getSubscriptionConfig() {
        return config;
    } 
        
    ...

When you implement your streams application, you will use your subscriber implementation. The getSubscriptionConfig() method on the subscriber is how your publisher finds out what tables to follow, and so forth. See Using a Streams Publisher.

The expiration time for an empty stream can be specified using the NoSQLSubscriptionConfig.setEmptyStreamDuration() method. The expiration time will begin only when a stream becomes empty after which the publisher would shut down the empty stream. The default empty stream expiration time is 60 seconds. The user can override the default empty stream expiration time by the setEmptyStreamDuration() method.

In this section, we have shown only a few options that you can set using NoSQLSubscriptionConfig. For a complete list of configuration options, see NoSQLSubscriptionConfig and NoSQLSubscriptionConfig.Builder in the Java Direct Driver API Reference.