Mobile workshop: Data Orchestration: Couchbase Connect 2015

19
COUCHBASE MOBILE DATA ORCHESTRATION

Transcript of Mobile workshop: Data Orchestration: Couchbase Connect 2015

Page 1: Mobile workshop: Data Orchestration: Couchbase Connect 2015

COUCHBASE  MOBILE  DATA  ORCHESTRATION

Page 2: Mobile workshop: Data Orchestration: Couchbase Connect 2015

2

Page 3: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.3

Data Routing

Dat

aD

ata

Page 4: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.4

Data Routing

Dat

a

Data

Dat

a

Page 5: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.5

Data Routing

Data

Data

Dat

aD

ata

Page 6: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.6

Data Routing

Data

Data

Data

Dat

aDa

ta

Page 7: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.7

Data Routing

Data

Data

Data Data

Dat

aD

ata

Page 8: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.8

Data Routing

Data

Data

Data

Data

Dat

aD

ata

Page 9: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.

Data  Model  

9

Page 10: Mobile workshop: Data Orchestration: Couchbase Connect 2015

Sync  Function

Page 11: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.

Sync  Gateway

▪ channel(name)  ▪ access(username,  channelname)  ▪ role(username,  rolename)  ▪ requireUser(username)  ▪ require(rolename)  ▪ requireAccess(channels)

11

Page 12: Mobile workshop: Data Orchestration: Couchbase Connect 2015

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

Page 13: Mobile workshop: Data Orchestration: Couchbase Connect 2015

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

Page 14: Mobile workshop: Data Orchestration: Couchbase Connect 2015

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

Page 15: Mobile workshop: Data Orchestration: Couchbase Connect 2015

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

Page 16: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©2014  Couchbase  Inc.

Sync  Gateway

▪ Executed  on  every  document  ▪Written  in  JavaScript  ▪ Pure  function  ▪ Can  be  changed  at  any  time

16

Page 17: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©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

Page 18: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©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

Page 19: Mobile workshop: Data Orchestration: Couchbase Connect 2015

©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