Data Subscriptions: Maintenance Operations



DocumentSubscriptions class

The DocumentSubscriptions class is the class that manages all interaction with the data subscriptions.
The class is available through DocumentStore's Subscriptions property.
Method Signature Return type Description
Create(SubscriptionCreationOptions options, string database) string Creates a new data subscription.
Create(SubscriptionCreationOptions criteria, string database) string Creates a new data subscription.
Create(SubscriptionCreationOptions criteria, string database) string Creates a new data subscription.
CreateAsync(SubscriptionCreationOptions options, string database) Task<string> Creates a new data subscription.
CreateAsync(Expression<Func<T, bool>> predicate, SubscriptionCreationOptions options, string database) Task<string> Creates a new data subscription.
Delete(string name, string database) void Deletes subscription.
DeleteAsync(string name, string database) Task Deletes subscription.
DropConnection(string name, string database) void Drops all existing subscription connections with workers.
DropConnectionAsync(string name, string database) Task Drops all existing subscription connections with workers.
DropSubscriptionWorker(SubscriptionWorker worker, string database = null) void Drops an existing subscription connection with a worker
Enable(string name, string database) void Enables existing subscription.
EnableAsync(string name, string database) Task Enables existing subscription.
Disable(string name, string database) void Disables existing subscription.
DisableAsync(string name, string database) Task Disables existing subscription.
GetSubscriptions(int start, int take, string database) List<SubscriptionState> Returns subscriptions list.
GetSubscriptionsAsync(int start, int take, string database) Task<List<SubscriptionState>> Returns subscriptions list.
GetSubscriptionState(string subscriptionName, string database) SubscriptionState Get specific subscription state.
GetSubscriptionStateAsync(string subscriptionName, string database) Task<SubscriptionState> Get specific subscription state.
GetSubscriptionWorker(string subscriptionName, string database) SubscriptionWorker<T> Generates a subscription worker, using default configurations, that processes documents deserialized to T type .
GetSubscriptionWorker(string subscriptionName, string database) SubscriptionWorker<dynamic> Generates a subscription worker, using default configurations, that processes documents in its raw BlittableJsonReader, wrapped by dynamic object.
GetSubscriptionWorker(SubscriptionWorkerOptions options, string database) SubscriptionWorker<T> Generates a subscription worker, using default configurations, that processes documents deserialized to T type .
GetSubscriptionWorker(SubscriptionWorkerOptions options, string database) SubscriptionWorker<dynamic> Generates a subscription worker, using default configurations, that processes documents in its raw BlittableJsonReader, wrapped by dynamic object.
Update(SubscriptionUpdateOptions options, string database = null) string Updates an existing data subscription.
UpdateAsync(SubscriptionUpdateOptions options, string database = null, CancellationToken token = default) Task<string> Updates an existing data subscription.

Deletion

Subscriptions can be entirely deleted from the system.

This operation can be very useful in ad-hoc subscription scenarios when a lot of subscriptions tasks information may accumulate, making tasks management very hard.

void Delete(string name, string database = null);
Task DeleteAsync(string name, string database = null, CancellationToken token = default);

usage:

store.Subscriptions.Delete(subscriptionName);

Dropping connection

Subscription connections with workers can be dropped remotely.
A dropped worker will not try to reconnect to the server.

void DropConnection(string name, string database = null);
Task DropConnectionAsync(string name, string database = null, CancellationToken token = default);

usage:

store.Subscriptions.DropConnection(subscriptionName);

Disabling subscription

Existing subscriptions can be disabled remotely.

void Disable(string name, string database = null);
Task DisableAsync(string name, string database = null, CancellationToken token = default);

usage:

store.Subscriptions.Disable(subscriptionName);

Enabling subscription

Existing subscriptions can be enabled remotely.
This operation can be useful for already disabled subscriptions. A newly created subscription is enabled initially.

void Enable(string name, string database = null);
Task EnableAsync(string name, string database = null, CancellationToken token = default);

usage:

store.Subscriptions.Enable(subscriptionName);

Updating subscription

See example and API description.

string Update(SubscriptionUpdateOptions options, string database = null);

Task<string> UpdateAsync(SubscriptionUpdateOptions options, string database = null,
                    CancellationToken token = default);

Getting subscription status

SubscriptionState GetSubscriptionState(string subscriptionName, string database = null);
Task<SubscriptionState> GetSubscriptionStateAsync(string subscriptionName, string database = null, CancellationToken token = default);

usage:

var subscriptionState = store.Subscriptions.GetSubscriptionState(subscriptionName);

SubscriptionState

Member Type Description
Query string Subscription's RQL like query.
LastBatchAckTime DateTime? Last time a batch processing progress was acknowledged.
NodeTag string Processing server's node tag
MentorNode string The mentor node that was manually set.
SubscriptionName string Subscription's name, and also its unique identifier
SubscriptionId long Subscription's internal identifier (cluster's operation etag during subscription creation)
ChangeVectorForNextBatchStartingPoint string The Change Vector from which the subscription will begin sending documents. This value is updated on batch acknowledgement, and can also be set manually.
Disabled bool If true, subscription will not allow workers to connect
LastClientConnectionTime DateTime? Time when last client was connected (value sustained after disconnection)