Changes API: How to subscribe to replication conflicts?

Replication conflicts, for both documents and attachments, can be tracked using ForAllReplicationConflicts method available in changes API.

Syntax

IObservableWithTask<ReplicationConflictNotification>
	ForAllReplicationConflicts();
Return value
IObservableWithTask<ReplicationConflictNotification> Observable that allows to add subscriptions to notifications for all replication conflicts.

Example

IDisposable subscription = store.Changes()
	.ForAllReplicationConflicts()
	.Subscribe(conflict =>
	{
		if (conflict.ItemType == ReplicationConflictTypes.DocumentReplicationConflict)
		{
			Console.WriteLine("Conflict detected for {0}. Ids of conflicted docs: {1}. " +
							  "Type of replication operation: {2}",
							  conflict.Id,
							  string.Join(", ", conflict.Conflicts),
							  conflict.OperationType);
		}
	});

Automatic document conflict resolution

In RavenDB client you have an opportunity to register conflict listeners which are used to resolve conflicted document. However this can happen only if you get the conflicted document. The ability to subscribe to the replication conflicts gives the client more power. Now if you listen to the conflicts and have any conflict listener registered, the client will automatically resolve the conflict right after the arrival of the notification.

Remarks

Information

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