Enterprise Architect's Perspective of Couchbase with N1QL: Couchbase Connect 2015
Mobile workshop: Data Orchestration: Couchbase Connect 2015
-
Upload
couchbase -
Category
Technology
-
view
244 -
download
1
Transcript of Mobile workshop: Data Orchestration: Couchbase Connect 2015
COUCHBASE MOBILE DATA ORCHESTRATION
2
©2014 Couchbase Inc.3
Data Routing
Dat
aD
ata
©2014 Couchbase Inc.4
Data Routing
Dat
a
Data
Dat
a
©2014 Couchbase Inc.5
Data Routing
Data
Data
Dat
aD
ata
©2014 Couchbase Inc.6
Data Routing
Data
Data
Data
Dat
aDa
ta
©2014 Couchbase Inc.7
Data Routing
Data
Data
Data Data
Dat
aD
ata
©2014 Couchbase Inc.8
Data Routing
Data
Data
Data
Data
Dat
aD
ata
©2014 Couchbase Inc.
Data Model
9
Sync Function
©2014 Couchbase Inc.
Sync Gateway
▪ channel(name) ▪ access(username, channelname) ▪ role(username, rolename) ▪ requireUser(username) ▪ require(rolename) ▪ requireAccess(channels)
11
function(doc, oldDoc) {
if (doc.type == "task") {
channel("list-" + doc.list_id);
} else if (doc.type == "list") {
channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id);
} else if (doc.type == "profile") {
access(doc._id, "profiles");
}
}{ "_id": "[email protected]", "type": "profile"}
Sync Gateway
list-123 list-453 profiles
Sync Function
function(doc, oldDoc) {
if (doc.type == "task") {
channel("list-" + doc.list_id);
} else if (doc.type == "list") {
channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id);
} else if (doc.type == "profile") {
access(doc._id, "profiles");
}
}
{ "_id": "123" "type": "list", "title": "Home List", "owner": "[email protected]",
"members": ["[email protected]","[email protected]"
]}
Sync Gateway
list-123 list-453 profiles
Sync Function
function(doc, oldDoc) {
if (doc.type == "task") {
channel("list-" + doc.list_id);
} else if (doc.type == "list") {
channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id);
} else if (doc.type == "profile") {
access(doc._id, "profiles");
}
}{ "_id": "999" "type": "task", "list_id": "123", "title": "Buy some hummus"}
Sync Gateway
list-123 list-453 profiles
Sync Function
function(doc, oldDoc) {
if (doc.type == "task") {
channel("list-" + doc.list_id);
} else if (doc.type == "list") {
channel("list-" + doc._id); access(doc.owner, "list-" + doc._id); access(doc.members, "list-" + doc._id);
} else if (doc.type == "profile") {
access(doc._id, "profiles");
}
}
{ "_id": "123" "type": "list", "title": "Home List", "owner": "[email protected]",
"members": ["[email protected]","[email protected]"
]}
Sync Gateway
list-123 list-453 profiles
Sync Function
©2014 Couchbase Inc.
Sync Gateway
▪ Executed on every document ▪Written in JavaScript ▪ Pure function ▪ Can be changed at any time
16
©2014 Couchbase Inc.
User Context{ "authentication_handlers": [ "default", "cookie" ], "ok": true, "userCtx": { "channels": { "list-02883035-5a2f-4862-b441-ea46254afda3": 60130, "list-e6941937-6fa3-4a56-973a-2c0f992fbea4": 129727, "list-f35902a0-8333-43d0-b383-6ee46efc2dd0": 129719, "profiles": 59264 }, "name": "[email protected]" }} 17
©2014 Couchbase Inc.
Replications
facebookAuthenticator = AuthenticatorFactory.createFacebookAuthenticator(accessToken);
pull = db.createPullReplication(SYNC_URL);pull.setAuthenticator(facebookAuthenticator);pullReplication.setContinuous(true);
push = db.createPushReplication(SYNC_URL);push.setAuthenticator(facebookAuthenticator);pushReplication.setContinuous(true);
pull.start();push.start();
18
©2014 Couchbase Inc.
Replications
db.createPullReplication(url); // replicatorList<String> channels = new ArrayList<String>();channels.add("list-UHFIEJOI-FNOEWF-ODIDIW");pull.setChannels(channels); // only this channel
19