Changes API: How to subscribe to replication conflicts?

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

Syntax

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

Example

Closeable subscription = store
  .changes()
  .forAllReplicationConflicts()
  .subscribe(Observers.create(new Action1<ReplicationConflictNotification>() {
    @Override
    public void apply(ReplicationConflictNotification conflict) {
      if (ReplicationConflictTypes.DOCUMENT_REPLICATION_CONFLICT.equals(conflict.getItemType())) {
        System.out.println("Conflict detected for " + conflict.getId());
      }
    }
  }));

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 then the client will automatically resolve the conflict right after the arrival of the notification.