Previous Next JavaScript must be enabled to correctly display this content

## Using NoSQLSubscription

`oracle.kv.pubsub.NoSQLSubscription` is used to control your subscription. It is used to request operations from the subscribed tables, to perform checkpoints, terminate the stream, and so forth. It is used as a part of your `NoSQLSubscriber` implementation.

The `NoSQLSubscription` interface extends `org.reactivestreams.Subscription`, so it is sufficient for your `NoSQLSubscription` implementation class to extend `NoSQLSubscription`. When your implementation class implements `NoSQLSubscriber.onSubscribe()`, you will usually call `NoSQLSubscription.request()`, which asks for an initial set number of events to be delivered to the subscriber (these are consumed using `NoSQLSubscriber.onNext()`):

    ...
    private NoSQLSubscription subscription;
    ...

    @Override
    public void onSubscribe(Subscription s) {
        subscription = (NoSQLSubscription) s;
        // request 100 store operations be streamed to this
        // subscriber.
        s.request(100);
        }

The important actions that you can take with your `NoSQLSubscription` object are:

- Cancel the stream using `NoSQLSubscription.cancel()`.

- Request more operations from the subscribed table.

  If you want to stream infinite number of operations, you can use `Long.MAX_VALUE`, which allows to stream for 584 years, assuming that the subscriber can process 1 billion operations per second.

  If the request is made at the beginning of the application's runtime before any operations have been consumed, then the operations will begin from the location identified by `NoSQLSubscriptionConfig.setStreamMode()`. If the request is made after operations have been consumed, then the operations will begin at the point in the stream immediately after the last consumed operation. For more information, see NoSQLStreamMode.

- Take a checkpoint. See Using Checkpoints for information about checkpoints.

- Get a list of currently subscribed tables anytime during the lifetime of the stream using `NoSQLSubscription.getSubscribedTables()` method. `SubscriptionFailureException` would be raised if the subscription is canceled or has shut down.

- Add a table to the running subscription stream asynchronously using `NoSQLSubscription.subscribeTable()` method. The change result will be signaled via the callback `NoSQLSubscriber.onChangeResult()` method.

- Remove a table from the running subscription stream asynchronously using `NoSQLSubscription.unsubscribeTable()` method. The change result will be signaled via the callback `NoSQLSubscriber.onChangeResult()` method.

For a complete list of operations supported by `NoSQLSubscription`, see NoSQLSubscription in the Java Direct Driver API Reference.