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

IDisposable subscription = store
    .Changes()
    .ForIndex("Orders/All")
    .Subscribe(
        change =>
        {
            switch (change.Type)
            {
                case IndexChangeTypes.None:
                    //Do someting
                    break;
                case IndexChangeTypes.BatchCompleted:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexAdded:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexRemoved:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexDemotedToIdle:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexPromotedFromIdle:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexDemotedToDisabled:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexMarkedAsErrored:
                    //Do someting
                    break;
                case IndexChangeTypes.SideBySideReplace:
                    //Do someting
                    break;
                case IndexChangeTypes.Renamed:
                    //Do someting
                    break;
                case IndexChangeTypes.IndexPaused:
                    //Do someting
                    break;
                case IndexChangeTypes.LockModeChanged:
                    //Do someting
                    break;
                case IndexChangeTypes.PriorityChanged:
                    //Do someting
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        });

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

IDisposable subscription = store
    .Changes()
    .ForAllIndexes()
    .Subscribe(change => Console.WriteLine("{0} on index {1}", change.Type, change.Name));

IndexChange

Properties

Name Type Description
Type IndexChangeTypes Change type
Name string Index name
Etag long? Index Etag

IndexChangeTypes

IndexChangeTypes (enum flags)

Members

Name Value
None 0
BatchCompleted 1
IndexAdded 8
IndexRemoved 16
IndexDemotedToIdle 32
IndexPromotedFromIdle 64
IndexDemotedToDisabled 256
IndexMarkedAsErrored 512
SideBySideReplace 1024
Renamed 2048
IndexPaused 4096
LockModeChanged 8192
PriorityChanged 16384

Remarks

Information

To get more method overloads, especially the ones supporting delegates, please add Reactive Extensions Core package to your project.