Skip to main content

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
indexNamestringName of an index for which notifications will be processed.
Return value
IObservableWithTask<IndexChangeNotification>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.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
IObservableWithTask<IndexChangeNotification>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));

Remarks

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