上一篇http://www.cnblogs.com/2018/archive/2011/02/22/1961654.html 对这个框架一个总体介绍,这篇通过SDK内带的例子和一个综合的例子描述一下这个框架的使用

[例子基于SDK2.1]

SDK的例子

C:\Program Files (x86)\Microsoft SDKs\Microsoft Sync Framework\2.1\Samples

WebSharingAppDemo-CEProviderEndToEnd

运行效果如上图,可以进行SQL、SQLCE数据库的相互同步

Sync101RCA_Cached和其他例子展示了Provider等的实现,可参考其中的说明

基本使用

使用这个框架进行数据库同步涉及的几个方面:

Ø Provisioning:对数据库架构和内容进行修改以记录修改的内容,为同步做准备

Ø Synchronizing:同步过程,利用以上的信息进行信息的传递

Ø Snapshot:在一个同步好的数据基础上建立快照,这样其他的客户端可以快速的部署

几个场景的例子

详细代码参考:http://cid-56b433ad3d1871e3.office.live.com/self.aspx/.Public/SyncTest.rar

具体代码的使用如下:

Database

N-Tier的同,SQl Server和SQL CE

Contracts: 接口定义

SqlWebSvc:WCF服务

SyncClient:客户端端

1.  建立SyncDB数据库,执行Data.edmx.sqldemoData.sql建立表和数据
2.  启动SqlWebSvc服务
3.  启动SyncClient
a)  先Provison服务端数据库,定义出同步的表和条件[只要一次即可,需要修改可以DeProvision或使用1的步骤重建]
b)  此时可远程同步[界面的中其他本地同步、架构建立只是说明]
c)   快照:只要有一个同步好的数据库,这个文件就可以拷贝到其他的客户端,对于大数据量的初始化很有用
     
 
总结:
Ø  数据的Provision和Deprovision简单
Ø  代码稍微多一些

Database2

类似CustomerProvider的同步

数据库Provision在Custome_SyncSamplesDb.sql建立

WCFService:服务端

SyncClient:客户端

1. 使用Custome_SyncSamplesDb.sql建立数据库和表

2. 运行WCFService

3. 运行SyncClient,可以看到同步的信息

总结:
Ø  数据的Provision和Deprovision需要通过脚本编写,采用SQL Server Tracking或自定义的形式

DBCache-IDE

VS IDE提供的支持,编程模型更简单

DataService:服务端

PresentationTier:客户端

1. 使用Northwind.sql建立数据库和表

2. 运行DataService服务

3. 运行PresentationTier

总结

Ø 提供了一系列的设置简化同步操作

Ø 只能针对SQL Server系列的数据库

Offline

SDK中Synchronizing Databases /Offline-Only Scenarios的例子

Tracking Changes in the Server Database

Use a Custom Change Tracking System

展示了以上两种跟踪变化的形式

Custome_SyncSamplesDb.sqlCustomeChangeTrack.cs

SqlServer_ChangeTracking.sqlSqlserverChangeTrack.cs

以上的脚本和代码配合可以完成同步的过程,通过这个可以了解更多的实现细节,对自定义Provider提供一些帮助

Code Specific To N-Tier

在SDK文档How to: Deliver Changes in Batches (SQL Server)“How to: Deliver Changes in Batches (SQL Server)”这个主题下有详细的说明,注记如下:

The remainder of the code examples apply only to the n-tier scenario in WebSharingAppDemo. The relevant n-tier code is contained in three files:

· The service contract: IRelationalSyncContract

· The Web service: RelationalWebSyncService

· The proxy: RelationalProviderProxy

The two providers SqlSyncProvider and SqlCeSyncProvider both inherit from RelationalSyncProvider, so this code applies to both providers. Additional store-specific functionality is separated into proxy and service files for each type of provider.

To understand how batching works in an n-tier scenario, consider a synchronization session in which the server is the source and the client is the destination. After changes have been written to the local directory on the server, the following process occurs for downloaded changes:

1. The GetChangeBatch method is called on the client proxy. As demonstrated later in the sample code, this method should include specific code to handle batching.

2. The service gets a batch file from SqlSyncProvider. The service removes the complete path information and sends only the file name over the network. This prevents exposing the directory structure of the server to the clients.

3. The proxy call to GetChangeBatch returns.

1. The proxy detects that changes are batched so it calls DownloadBatchFile by passing the batch file name as an argument.

2. The proxy creates a unique directory (if one doesn’t exist for the session) under RelationalProviderProxy.BatchingDirectory to hold these batch files locally. The directory name is the replica ID of the peer that is enumerating changes. This ensures that the proxy and service have one unique directory for each enumerating peer.

4. The proxy downloads the file and stores it locally. The proxy replaces the filename in the context with the new full path to the batch file on the local disk.

5. The proxy returns the context back to the orchestrator.

6. Repeat steps 1 through 6 until the last batch is received by proxy.

The following process occurs for uploaded changes

1. The orchestrator calls ProcessChangeBatch on the proxy.

2. The proxy determines that it is a batch file, so it performs the following steps:

1. Removes the complete path information and sends only the file name over the network.

2. Calls HasUploadedBatchFile to determine if the file has already been uploaded. If it has, step C is not necessary.

3. If HasUploadedBatchFile returns false, calls UploadBatchFile on the service, and uploads the batch file contents.

The service will receive the call to UploadBatchFile and store the batch locally. Directory creation is similar to step 4 above.

4. Calls ApplyChanges on the service.

3. The server receives the ApplyChanges call and determines that it is a batch file. It replaces the filename in the context with the new full path to the batch file on the local disk.

4. The server passes the DbSyncContext to local SqlSyncProvider.

5. Repeat steps 1 through 6 until the last batch is sent.

转载于:https://www.cnblogs.com/2018/archive/2011/02/23/1961657.html

数据同步框架MS Sync Framework-不同场景使用例子和简要分析相关推荐

  1. MetaQ 简单使用(数据同步框架)

    数据同步通用框架说明 框架说明 数据同步工具用来对两个系统或者多个系统的数据进行同步处理,框架能够实现项目开发人员只需配置两边系统需的业务数据,不需要关系数据是如何实现同步的,框架底层数据传输技术使用 ...

  2. datax 定时执行多个job_数据同步神器Datax源码重构

    每日一句永远不要认为我们可以逃避, 我们的每一步都决定着最后的结局, 我们的脚步正在走向我们自己选定的终点.Do not ever think about that we can escape , o ...

  3. 离线数据同步平台datax+报表可视化平台metabase

    datax DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL.Oracle.SqlServer.Postgre.HDFS.Hive.ADS.HBase.TableS ...

  4. datax 导入数据中文乱码_浅谈数据同步之道

    数据同步,顾名思义就是不同系统的数据进行同步处理.而业务系统所涉及的数据库同步是重中之重,虽然大部分数据库都提供了导入导出的工具,但是数据存储到各个地方,Hive.Hbase.MySQL.Oracle ...

  5. 离线数据同步神器:DataX,支持几乎所有异构数据源的离线同步到MaxCompute

    2019独角兽企业重金招聘Python工程师标准>>> 摘要: 概述 DataX 是阿里巴巴集团内被广泛使用的离线数据同步工具/平台,实现包括 MySQL.Oracle.SqlSer ...

  6. rsync安装与配置使用 数据同步方案(centos6.5)

    rsync + crond   ==定时数据同步 sersync(inotify)  + rsync  ==实时数据同步,利用rsync实现 ##应用场景 ..1 主备服务器之间同步数据定时    = ...

  7. datax实现mysql数据同步

    前言 DataX 是阿里内部广泛使用的离线数据同步工具/平台,可以实现包括 MySQL.Oracle.HDFS.Hive.OceanBase.HBase.OTS.ODPS 等各种异构数据源之间高效的数 ...

  8. sql 不同数据库同步数据_什么是SQL数据同步

    sql 不同数据库同步数据 SQL Data Sync is a service that allows synchronizing data across multiple Azure SQL da ...

  9. linux下实现web数据同步的四种方式(性能比较)

    实现web数据同步的四种方式 ======================================= 1.nfs实现web数据共享 2.rsync +inotify实现web数据同步 3.rs ...

最新文章

  1. 使用模板库的几个注意点
  2. php数组的声明和类型
  3. 使textarea支持tab缩进
  4. NPAPI插件开发学习:NPAPI和NPRuntime的介绍
  5. python基础:pip和虚拟环境
  6. linux chmod 777 r,chmod -R 777 的3种补救办法,附有linux chmod命令语法和结构详解
  7. AppFabric 1.1: installation error 错误代码 1603 windows server 2016 sharepoint 2019 Preparation Tool
  8. 稳妥方法论:如何完整地设计出游戏关卡及场景
  9. 十大程序员最实用的技术社区网站
  10. python参数类型为uint8_Python 改变数组类型为uint8的实现
  11. 大白话式粗浅地聊聊NLP语言模型
  12. OkHttp3源码详解(四)缓存策略,万分膜拜
  13. Golang环境变量设置(二)--GOMODULEGOPROXY
  14. 【信管2.6】项目可研(二)详细可行性研究
  15. excel VLOOKUP查找
  16. java字符串转成utf-8_将字符串的编码格式转换为utf-8
  17. Linux(十二)中断系统
  18. Android 替换原生输入法
  19. 如何评估用户需求的价值?关键看4方面
  20. MOOC战德臣数据库课程自用笔记_5_SQL复杂查询与视图

热门文章

  1. 我参与的一个项目总结
  2. ubuntu系统debootstrap的使用之二:启动
  3. 【netty】Netty并发工具-Promise
  4. 95-30-017-Channel-NioServerSocketChannel
  5. 【kafka】Attempted to write a non-default produerId at version 1
  6. 【flink】Flink 使用IntelliJ IDEA 进行远程调试代码
  7. 【ElasticSearch】Es 源码之 MetaStateService 源码解读
  8. 40-10-010-运维-kafka-2.11-基本操作
  9. 【Elasticsearch】索引和查询性能调优的21条建议-以及调优参数
  10. SpringBoot:@ConfigurationProperties注解使用与源码