Rob Sanders
Rob Sanders

Reputation: 5347

Couchbase Lite 2.0 Replication

I am upgrading our systems from couchbase lite 1.5 to 2.0 and have come across a replication issue. I am creating a continuous push and pull replicator which pulls changes when the app starts but does not continue to sync throughout the lifetime of the app.

Here is my replicator creation code:

public void StartSync(Uri syncEndpoint, string username, ISecureString password)
        {
            if (_database == null)
            {
                throw new DataHandlerException(DataHandlerError.DatabaseDoesntExist);
            }

            var endpoint = new URLEndpoint(syncEndpoint);
            var config = new ReplicatorConfiguration(_database, endpoint)
            {
                Authenticator = new BasicAuthenticator(username, password.ToString()),
                Continuous = true
            };

            _replicator = new Replicator(config);
            _replicator.AddChangeListener((s, a) =>
            {
                OnSyncChange(a.Status);
            });

            _replicator.Start();
        }

I also have several live queries set up using the new syntax:

var token = query.AddChangeListener(OnQueryUpdated); // start live query

The live query callback never gets called bu I assume this is because the replication is not working.

Has anyone come across this issue or have any examples of best practice with Couchbase Lite 2.0?

UPDATE:

I have discovered that this issue was caused by an problem with web sockets which is the protocol Couchbase sync gateway is now using. I had to check my nginx settings and restart all my services to correct this issue.

Upvotes: 0

Views: 232

Answers (1)

Rob Sanders
Rob Sanders

Reputation: 5347

The issues was that nginx needed to be properly configured in order to work with the new websockets protocol used by sync gateway in version 2.0.0

The settings can be found in the /etc/nginx/sites-available/default file and the official settings according to the sync gateway docs are:

location / {
    proxy_pass              http://sync_gateway;
    proxy_pass_header       Accept;
    proxy_pass_header       Server;
    proxy_http_version      1.1;
    keepalive_requests      1000;
    keepalive_timeout       360s;
    proxy_read_timeout      360s;
    proxy_set_header        Upgrade $http_upgrade;
    proxy_set_header        Connection "upgrade";
}

I have, however, found that this works when the application running couchbase lite first opens the connection but continuous replication can still be an issue. A possible work around is to point the client directly at sync gateway and not use nginx at all. This needs more investigation.

Upvotes: 1

Related Questions