57

Introduction to Couchbase (Chinese)

Embed Size (px)

Citation preview

Page 1: Introduction to Couchbase (Chinese)
Page 2: Introduction to Couchbase (Chinese)

Couchbase  for  Mobile  

Larry  Liu  (刘栋) - 高级工程师

[email protected]

Page 3: Introduction to Couchbase (Chinese)

Couchbase  Lite  

唯一的移动平台专用NoSQL数据库

Page 4: Introduction to Couchbase (Chinese)

主机-绿色终端

百万级用户

千级应用

个人电脑 客户端/服务器 局域网/互联网

亿级用户

万级应用

云,移动设备和应用,无数其他的东西

十亿级用户

百万级应用

移动互联网 -- 下一代技术平台  

1980   1990   2020+  2000   2010  

Page 5: Introduction to Couchbase (Chinese)

移动应用 - 下一代应用

 Couchbase    Server  

   

单个用户的交互 •  语音,短信 •  个人应用

多用户交互 • 群和社交应用

(脸书,微信,微博, 游戏,视频)

医院的本地传感应用

与企业沟通

Page 6: Introduction to Couchbase (Chinese)

JSON  Anywhere

Couchbase  Server  

•  设备上的JSON

开发者越来越喜欢NoSQL数据库

•  传输中的JSON

不需要数据转换

•  云端的JSON

灵活的数据模型

高性能

以扩展性

ServerSync GatewayLiteJS N

JS N

JS N

Page 7: Introduction to Couchbase (Chinese)

马上开始

• 下载 Couchbase Lite

• 下载 Grocery Sync代码

• 复制Couchbase Lite到Grocery Sync应用的framework文件夹

• 运行

Page 8: Introduction to Couchbase (Chinese)

1.  下载  Couchbase  Lite  

•  www.couchbase.com/communiCes/cn/couchbase-­‐lite  

Page 9: Introduction to Couchbase (Chinese)

2.  下载  Grocery  Sync  •  github.com/couchbaselabs/Grocery-­‐Sync-­‐iOS  

Page 10: Introduction to Couchbase (Chinese)

3. 复制Couchbase Lite

•     option

Page 11: Introduction to Couchbase (Chinese)

4. 运行

•     

Page 12: Introduction to Couchbase (Chinese)

步骤  •  Couchbase Server URL: http://10.17.4.11:8091/index.html

•  同步URL:

http://10.17.4.11:4984/sync_gateway

•  启动sync_gateway:

./sync_gateway -url http://10.17.4.11:8091 &

•  开通GUEST权限:

curl -X PUT localhost:4985/sync_gateway/_user/GUEST --data '{"disabled":false, "admin_channels":["public"]}'

•  检查数据

curl http://localhost:4985/sync_gateway/_all_docs

•  检查键

curl http://localhost:4985/sync_gateway/1444EC46-B921-4070-B0FC-BA37E426C7C7

Page 13: Introduction to Couchbase (Chinese)

现场演示

Page 14: Introduction to Couchbase (Chinese)

完整的移动互联网解决方案  

Page 15: Introduction to Couchbase (Chinese)

架构  

   

SERVER  3      

SERVER  1      

SERVER  2  

Couchbase  Server  

   

Channel

Sync  Gateway  

Channel

   

Channel

Sync  Gateway  

Channel

Couchbase  Lite  运行在 iOS  和 Android  上

企业内部部署 云端部署

Page 16: Introduction to Couchbase (Chinese)

Couchbase  Lite  唯一的移动设备NoSQL数据库

• 特色 ­  超轻量,安全的JSON数据库

­  原生支持iOS,Android, REST API

­  完整的文档管理,索引,查询,和同步功能

­ 强大的冲突管理

Lite

Couchbase  Lite    

Android  

Couchbase  Lite    iOS  

Page 17: Introduction to Couchbase (Chinese)

在Couchbase Lite时代之前…  •  在本地,可以使用SQLite或苹果 Core Data

­  有利于使用关系模型或非数据密集性的应用

­  不利于对更直观和灵活的数据存储感兴趣的移动开发者

•  同步和存储可以使用文件分享服务

­  这些服务不是数据库,不能提供数据库所具有功能

•  或者可以使用MBaaS

­  不能提供离线体验。 我们仍然在一个偶尔连接的世界,一个好的应用必须考虑离线体验

Page 18: Introduction to Couchbase (Chinese)

Couchbase  Lite  全功能列表

功能   好处  

本地APIs 使用专門为iOS和Android优化的API管理移动数据库

REST APIs 基于你的开发需求, REST APIs 提供了一种替代的访问方法

JSON 支持 使用专为面向对象的移动应用设计的灵活的数据模型,即时适应你的应用程序需要并且对应用程序不造成影响

易于同步 只须几行代码就可以同步就绪;使开发者可以更专注于应用开发,

而不是同步

通过REST接口支持点对点 通过REST接口支持的点对点服务,使附近的设备即使离线也能够沟通

通过通道进行数据路由 使用户得到所需的数据来获得集中关联的体验

变化源 为开发者提供数据变化的可视化和通知

支持JSON的索引和查询 使用强大的二级索引来查询您设备上的数据

验证插件 利用现有的第三方验证服务例如脸书,不需要自己开发

支持设备和云端的附件 对二进制数据,例如图片和大文件,进行与JSON文档不同的管理,以获得不同的,更快的同步

Page 19: Introduction to Couchbase (Chinese)

为您服务

Lite

Couchbase  Lite    

Android  

Couchbase  Lite    iOS  

­ 使丰富数据密集型的本地应用成为可能

­ 使用JSON 数据,开发变的更快 ­ 使交互应用反映速度更快

­ 无论在线还是离线,应用总是可用

Page 20: Introduction to Couchbase (Chinese)

优点  

         JSON  Anywhere    

 

• 在设备上使用灵活的JSON,可以在不影响后台的同时,修改本地数据结构,并与本地数据工作

轻松同步  

• 毫不费力地使本地的更新,复制或协作共享同步到云端的数据库

• 随着数据和同步的增长,水平并可靠的扩展数据层

JSONJSONJSON

JSONJSON

Page 21: Introduction to Couchbase (Chinese)

Couchbase  Sync  Gateway  容易可靠的把数据同步到云端

•  功能

•  通过同步功能的API实现动态同步

•  易于管理

•  无缝扩展

•  好处

  开发时间减少90%

  可扩展到支持上百万的用户

Sync Gateway

Page 22: Introduction to Couchbase (Chinese)

同步原理  

Page 23: Introduction to Couchbase (Chinese)

采用通道来协作

• 对于每个文档,指定一组这个文档所属的通道

• 对于每个用户或设备,控制哪些通道是他们有权使用的

•  只复制文档的子集到设备上

­  用户定义的过滤功能

­  只需要让用户知道一个文档是否需要被复制

•  可以对用户进行验证

 

Page 24: Introduction to Couchbase (Chinese)

数据流

Server  3  Server  1   Server  2  

Couchbase  Server  

Channel

Sync  Gateway  

Channel Channel

Sync  Gateway  

Channel

Couchbase  Lite  for  iOS  and  Android  

Sync  Push  

Page 25: Introduction to Couchbase (Chinese)

数据流  

Server  3  Server  1   Server  2  

Couchbase  Server  

Channel

Sync  Gateway  

Channel Channel

Sync  Gateway  

Channel

Couchbase  Lite  for  iOS  and  Android  

JavaScript  Sync  Func@on  ↻

Page 26: Introduction to Couchbase (Chinese)

数据流  

Server  3  Server  1   Server  2  

Couchbase  Server  

Channel

Sync  Gateway  

Channel Channel

Sync  Gateway  

Channel

Couchbase  Lite  for  iOS  and  Android  

Store  Data  

Page 27: Introduction to Couchbase (Chinese)

数据流  

Server  3  Server  1   Server  2  

Couchbase  Server  

Channel

Sync  Gateway  

Channel Channel

Sync  Gateway  

Channel

Couchbase  Lite  for  iOS  and  Android  

TAP/UPR  

Page 28: Introduction to Couchbase (Chinese)

数据流  

Server  3  Server  1   Server  2  

Couchbase  Server  

Channel

Sync  Gateway  

Channel Channel

Sync  Gateway  

Channel

Couchbase  Lite  for  iOS  and  Android  

HTTP  Changes  

Page 29: Introduction to Couchbase (Chinese)

Doc  1   通道  A  

Doc  2  通道  A  

通道B  

通道A  &  B  

通道B  

Doc  1  Doc  2  

Doc  2  

Page 30: Introduction to Couchbase (Chinese)

数据路由

Dat

a D

ata

Page 31: Introduction to Couchbase (Chinese)

数据路由

Dat

a

Data

Dat

a

Page 32: Introduction to Couchbase (Chinese)

数据路由

Data

Dat

a D

ata

Page 33: Introduction to Couchbase (Chinese)

数据路由

Dat

a Da

ta

Page 34: Introduction to Couchbase (Chinese)

数据路由

Data

Data

Dat

a D

ata

Page 35: Introduction to Couchbase (Chinese)

数据路由

Data

Dat

a D

ata

Page 36: Introduction to Couchbase (Chinese)

Couchbase  Server  业界领先的NoSQL数据库

•  多种部署方案

­  内部部署

­  云端部署如Amazon

­  后台服务

• Couchbase云

Server

Page 37: Introduction to Couchbase (Chinese)

案例

Page 38: Introduction to Couchbase (Chinese)

Infinite  Campus  

课堂管理工具和内容分发平台

Page 39: Introduction to Couchbase (Chinese)

Infinite  Campus  问题提出

• 课堂参与度不高

• 学生无法理解课堂资料

• 没有现成的,面向全体学生的多媒体的材料

Page 40: Introduction to Couchbase (Chinese)

Infinite  Campus  挑战和难点

• 如何在学生们所喜爱的智能手机上使用移动或Web应用进行教学

• 如何利用实时把受到反馈并利用反馈有效的指导课堂

• 如何为学生在校内外提供丰富的材料和内容

Page 41: Introduction to Couchbase (Chinese)

Infinite  Campus  解决方案

•  教室可以通过智能手机和Web客户端准备符合国家标准的材料

•  教学内容分发到每个学生,并得到实时反馈来指导教学

•  内容可以用来做离线学习或作业;学生脱机学习的进展可以同步到Couchbase Server。学生一旦连线,就可以受到教室的评估。

Page 42: Introduction to Couchbase (Chinese)

移动教学 过去 现在

教室,黑板,一刀切式的教学 多媒体,自定进度,自适应,互动,随时随地

Page 43: Introduction to Couchbase (Chinese)

POS  过去 现在

大而古怪的机器,收据打印机,现金抽屉

简单,优雅的平板电脑,方正的按键, 电邮收据,触摸签名

Page 44: Introduction to Couchbase (Chinese)

花费管理  过去 现在

纸质的收据,手工表格输入, 纸质签名

电邮相片收据,电子签名

Page 45: Introduction to Couchbase (Chinese)

开始同步

只要5分钟!!!

Page 46: Introduction to Couchbase (Chinese)

原理浅探

•  架构

•  代码解析

Page 47: Introduction to Couchbase (Chinese)

应用程序运行时 (操作系统进程)

存储

Couchbase  Lite  

本地应用程序逻辑

同步

Page 48: Introduction to Couchbase (Chinese)

Couchbase  Lite  组件

键/值对JSON存储  

同步引擎

Map/Reduce  视图索引

查询引擎

应用程序  API  

Page 49: Introduction to Couchbase (Chinese)

Sync  Gateway  组件  

Sync  REST  API  

Couchbase 智能客户端

冲突管理

认证

同步函数 通道变化 追踪

第三方认证服务  

到客户端

到  Couchbase  Server  

Page 50: Introduction to Couchbase (Chinese)

代码解析

Page 51: Introduction to Couchbase (Chinese)

模型  

Task

List

Task Task

Document

“doc23” Docume

nt “doc82”

Document

“doc99”

Document “doc3”

Page 52: Introduction to Couchbase (Chinese)

JSON文档  

Page 53: Introduction to Couchbase (Chinese)

同步功能  

•  在Sync Gateway的配置文件中运行

•  访问控制

•  通道路由

•  验证更新

只需几行代码实现同步.  

可编程的同步

Page 54: Introduction to Couchbase (Chinese)

Sync  Gateway:  App  Logic  &  Storage  应用逻辑和存储  

Couchbase  Smart  Client  

Revision/Conflict  

Management  

App’s  Sync  Func@on  

to  Couchbase  Server  

 function(doc,  oldDoc)  {  …  requireUser(oldDoc.owner);  …  channel(doc.channel);  …  access(doc.members,  doc.roomID);  }  

rev 1 rev 2

rev 3a

rev 3b

Authen@ca@on  

Page 55: Introduction to Couchbase (Chinese)

集成    Couchbase  Lite的合作伙伴

hPps://marketplace.appcelerator.com/apps/6706?1396013098  

hPp://components.xamarin.com/view/couchbase-­‐lite/  

hPp://plugins.cordova.io/#/com.couchbase.lite.phonegap  

Couchbase  Lite  Plugin  for  PhoneGap  

Couchbase  Lite  for  Xamarin  

Couchbase  Lite  Titanium  

Page 56: Introduction to Couchbase (Chinese)

开始体验

mobile.couchbase.com/cn  

应用实例

• hXps://github.com/couchbaselabs/Grocery-­‐Sync-­‐iOS  

hXps://github.com/couchbaselabs/ToDoLite-­‐iOS  

Couchbase  Cloud  

hXp://www.couchbasecloud.com  

Page 57: Introduction to Couchbase (Chinese)

Q&A?  

中国Couchbase