6 Using Checkpoints

When a subscriber opens a subscription stream, it starts consuming events from the earliest available point in the stream, unless you specify a different start point. To begin consuming from another location, your application must have run and saved a checkpoint that represents a stream location. Use NoSQLSubscription.getCurrentPosition() to obtain the current stream position. This method returns as StreamPosition class. Use NoSQLSubscription.doCheckpoint() to run the actual checkpoint.

Running a checkpoint causes the current stream position to be saved in the store using the checkpoint table you identified when you configured your NOSQLSubscription instance. Only the latest checkpoint is saved to this table. If you want to save other checkpoints, you can serialize the StreamPosition class representing a checkpoint, and save it to disk or a database of your choice.

Note:

  • You are responsible for choosing a name for the checkpoint table. Be sure that the name is unique to your subscription. If you are using multiple subscriptions, make sure that each subscription has a unique name for its checkpoint table.

  • Checkpoint tables are used to store checkpoint-related information. Do not delete or change the table structure without consideration. If you delete the table, you lose the checkpoint for this subscription. If the subscription continues after its checkpoint table is deleted, at the next checkpoint, the subscriber will be unable to locate the expected checkpoint and will skip a checkpoint. The method onCheckpointComplete() captures the CheckpointFailureException error message.

    If you cancel the current subscription and re-create a new one, the new subscription will create the checkpoint for you at the beginning, as long as it has the privilege to do so.

The method NoSQLSubscription.doCheckpoint() runs asynchronously, so the call returns after the checkpoint is requested, and NoSQLSubscriber.onCheckpointComplete is called when the checkpoint is complete. TheCheckpointFailureException is raised if you call this method while there is another outstanding request for a checkpoint running for the same subscription.