Changes API: How to Subscribe to Time Series Changes
- Use the following methods to subscribe to Time Series Changes:
ForTimeSeries
Track all time series with a given nameForTimeSeriesOfDocument
Overload #1: Track a specific time series of a chosen document
Overload #2: Track any time series of a chosen documentForAllTimeSeries
Track all time series
The Subscribe method on the observable these methods return accepts only an IObserver object
by default.
To instead subscribe with a delegate, like the change => ... lambda used in the examples below,
add the System.Reactive package to your project.
This adds Subscribe overloads that take delegates, including ones with error and
completion handlers.
ForTimeSeries
Subscribe to changes in all time series with a given name, no matter which document they belong to,
using the ForTimeSeries method.
Syntax
IChangesObservable<TimeSeriesChange> ForTimeSeries(string timeSeriesName);
| Parameters | ||
|---|---|---|
| timeSeriesName | string | Name of a time series to subscribe to. |
| Return Value | |
|---|---|
| IChangesObservable<TimeSeriesChange> | Observable that allows to add subscriptions to time series notifications. |
Example
IDisposable subscription = store
.Changes()
.ForTimeSeries("Likes")
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});
ForTimeSeriesOfDocument
Use ForTimeSeriesOfDocument to subscribe to changes in time series of a chosen document.
- Two overload methods allow you to
- Track a specific time series of the chosen document
- Track any time series of the chosen document
Overload #1
Use this ForTimeSeriesOfDocument overload to track changes in a specific time series of the chosen document.
Syntax
IChangesObservable<TimeSeriesChange> ForTimeSeriesOfDocument(string documentId, string timeSeriesName);
| Parameters | ||
|---|---|---|
| documentId | string | ID of a document to subscribe to. |
| timeSeriesName | string | Name of a time series to subscribe to. |
| Return Value | |
|---|---|
| IChangesObservable<TimeSeriesChange> | Observable that allows to add subscriptions to time series notifications. |
Example
IDisposable subscription = store
.Changes()
.ForTimeSeriesOfDocument("companies/1-A", "Likes")
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});
Overload #2
Use this ForTimeSeriesOfDocument overload to track changes in any time series of the chosen document.
Syntax
IChangesObservable<TimeSeriesChange> ForTimeSeriesOfDocument(string documentId);
| Parameters | ||
|---|---|---|
| documentId | string | ID of a document to subscribe to. |
| Return Value | |
|---|---|
| IChangesObservable<TimeSeriesChange> | Observable that allows to add subscriptions to time series notifications. |
Example
IDisposable subscription = store
.Changes()
.ForTimeSeriesOfDocument("companies/1-A")
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});
ForAllTimeSeries
Subscribe to changes in all time series using the ForAllTimeSeries method.
Syntax
IChangesObservable<TimeSeriesChange> ForAllTimeSeries();
| Return Value | |
|---|---|
| IChangesObservable<TimeSeriesChange> | Observable that allows to add subscriptions to time series notifications. |
Example
IDisposable subscription = store
.Changes()
.ForAllTimeSeries()
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});
TimeSeriesChange and TimeSeriesChangeTypes syntax
- TimeSeriesChange
- TimeSeriesChangeTypes
The notification object delivered to subscribers when a time series changes.
class TimeSeriesChange
{
TimeSeriesChangeTypes Type
string Name
string DocumentId
string CollectionName
DateTime From
DateTime To
string ChangeVector
}
| Property | Type | Description |
|---|---|---|
| Type | TimeSeriesChangeTypes | Time series change type enum |
| Name | string | Time Series Name |
| DocumentId | string | Time series Document Identifier |
| CollectionName | string | Time series document Collection Name |
| From | DateTime | Time series values From date |
| To | DateTime | Time series values To date |
| ChangeVector | string | Time series Change Vector |
enum TimeSeriesChangeTypes
{
None,
Put,
Delete,
Mixed,
}
| Name | Value |
|---|---|
| None | 0 |
| Put | 1 |
| Delete | 2 |
| Mixed | 3 |