I am trying to prototype a couchbase lite client that can sync with couchbase server database via sync gateway. Push replication is working fine, new document created by client can be replicated to server but any updates on the documents or existing documents on server cannot be replicated to client side. Below are the details of my setup:
Couchbase Server:
- version: Enterprise edition 7.1.3 build 3479 (installed using APT)
- OS: Ubuntu 20.04.2 LTS
- created one bucket named “get-started-bucket” with no replicas enabled
- created 3 users:
- username = sync_gateway, roles = Full Admin
- username = sync_gateway0, roles = Sync Gateway [get-started-bucket]
- username = sync_gateway1, roles = Sync Gateway Application [get-started-bucket:.]
Sync Gateway:
- version: couchbase-sync-gateway-enterprise_3.0.5_x86_64
- OS: Ubuntu 20.04.2 LTS
- configuration file:
{
"bootstrap": {
"server": "couchbase://0.0.0.0",
"username": "sync_gateway",
"password": "password",
"server_tls_skip_verify": true,
"use_tls_server": false
},
"api": {
"admin_interface_authentication": false,
"metrics_interface_authentication": false
},
"logging": {
"console": {
"enabled": true,
"log_level": "debug",
"log_keys": ["*"]
}
}
}
- created one database named traveldb (see images attached for database configuration, i.e. role, user, channel, etc.)
Couchbase Lite Client (using C):
- version: cblite v3.0.2 (install via apt)
- OS: Raspbian Buster (version 10)
- sample code to perform push and pull replication via sync gateway interface:
CBLError err;
CBLDatabase* database = CBLDatabase_Open(FLSTR("traveldb"), NULL, &err);
if(!database) {
fprintf(stderr, "Error opening database (%d / %d)\n", err.domain, err.code);
return;
}
CBLDocument* newTask = CBLDocument_CreateWithID(FLSTR("xyz"));
FLMutableDict properties = CBLDocument_MutableProperties(newTask);
FLMutableDict_SetString(properties, FLSTR("type"), FLSTR("task"));
FLMutableDict_SetString(properties, FLSTR("owner"), FLSTR("todo"));
FLMutableDict_SetUInt(properties, FLSTR("createdAt"), time(NULL) * 1000);
CBLDatabase_SaveDocument(database, newTask, &err);
CBLDocument_Release(newTask);
CBLEndpoint* targetEndpoint = CBLEndpoint_CreateWithURL(FLSTR("ws://192.168.3.152:4984/traveldb"), &err);
if(!targetEndpoint) {
printf("Failed to create endpoint...");
return;
}
CBLReplicatorConfiguration replConfig;
CBLAuthenticator* basicAuth = CBLAuth_CreatePassword(FLSTR("sgwuser2"), FLSTR("password"));
memset(&replConfig, 0, sizeof(replConfig));
replConfig.database = database;
replConfig.endpoint = targetEndpoint;
replConfig.authenticator = basicAuth;
replConfig.replicatorType = kCBLReplicatorTypePushAndPull;
replConfig.continuous = true;
replConfig.disableAutoPurge = true;
CBLReplicator* replicator = CBLReplicator_Create(&replConfig, &err);
CBLAuth_Free(basicAuth);
CBLEndpoint_Free(targetEndpoint);
if(!replicator) {
printf("Failed to create replicator...");
return;
}
CBLListenerToken* token = CBLReplicator_AddChangeListener(replicator, simpleChangeListener, NULL);
CBLReplicator_Start(replicator, false);
while(CBLReplicator_Status(replicator).activity != kCBLReplicatorStopped) {
printf("Waiting for replicator to stop...");
const CBLDocument* doc = CBLDatabase_GetDocument(database, FLSTR("xyz"), &err);
FLSliceResult docJson = CBLDocument_CreateJSON(doc);
printf("Document in JSON :: %.*s\n", (int)docJson.size, (const char *)docJson.buf);
usleep(500000);
}
CBLReplicator_Release(replicator);
**The document is updated on server by changing its value for the key “owner” but replicator on client side does not seem to be receiving any incoming messages from sync gateway.
Wondering what’s wrong with my configuration, any helps or suggestions would be much appreciated.
Thanks in advance~