You are currently browsing legacy 4.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Changes API: How to Subscribe to Index Changes

Following methods allow you to subscribe to index changes:

forIndex

Index changes for one index can be observed using forIndex method.

Syntax

IChangesObservable<IndexChange> forIndex(String indexName);

Parameters
indexName String Name of an index for which notifications will be processed.
Return value
IChangesObservable<IndexChange> Observable that allows to add subscriptions to notifications for index with given name.

Example

CleanCloseable subscription = store
    .changes()
    .forIndex("Orders/All")
    .subscribe(Observers.create(change -> {
        switch (change.getType()) {
            case NONE:
                // do something
                break;
            case BATCH_COMPLETED:
                // do something
                break;
            case INDEX_ADDED:
                // do something
                break;
            case INDEX_REMOVED:
                // do something
                break;
            case INDEX_DEMOTED_TO_IDLE:
                // do something
                break;
            case INDEX_PROMOTED_FROM_IDLE:
                // do something
                break;
            case INDEX_DEMOTED_TO_DISABLED:
                // do something
                break;
            case INDEX_MARKED_AS_ERRORED:
                // do something
                break;
            case SIDE_BY_SIDE_REPLACE:
                // do something
                break;
            case RENAMED:
                // do something
                break;
            case INDEX_PAUSED:
                // do something
                break;
            case LOCK_MODE_CHANGED:
                // do something
                break;
            case PRIORITY_CHANGED:
                // do something
                break;
            default:
                throw new IllegalArgumentException();
        }
    }));

forAllIndexes

Index changes for all indexex can be observed using forAllIndexes method.

Return value
IChangesObservable<IndexChange> Observable that allows to add subscriptions to notifications for all indexes.

Syntax

IChangesObservable<IndexChange> forAllIndexes();

Example

CleanCloseable subscription = store
    .changes()
    .forAllIndexes()
    .subscribe(Observers.create(change -> {
        System.out.println(change.getType() + " on index " + change.getName());
    }));

IndexChange

Properties

Name Type Description
Type IndexChangeTypes Change type
Name String Index name
Etag Long Index Etag

IndexChangeTypes

Name
NONE
BATCH_COMPLETED
INDEX_ADDED
INDEX_REMOVED
INDEX_DEMOTED_TO_IDLE
INDEX_PROMOTED_TO_IDLE
INDEX_DEMOTED_TO_DISABLED
INDEX_MARKED_AS_ERRORED
SIDE_BY_SIDE_REPLACE
RENAMED
INDEX_PAUSED
LOCK_MODE_CHANGED
PRIORITY_CHANGED