是否有通过网络同步数据列表的模式?
我有一个服务器应用程序,可以通过网络向多个客户端提供数据。您可以将数据想象为一个巨大的字符串列表。服务器上的数据可能会发生变化,需要在所有客户端上同步。
我目前正在使用这种方法:在初始连接时,客户端应用程序请求所有当前数据(可能是很多字节)。然后,它订阅任何数据的更新(添加、更改和删除)。
除非在发送初始数据列表和应用程序订阅更改之间服务器上的数据发生更改,否则这种方法可以正常工作 - 在这种情况下,客户端会错过一些更新并在不知情的情况下处理过时的数据。
我相信这是一个非常常见的场景,因此应该有一种模式可以解决这个问题。我正在使用 C# 4 和 WCF,但我相信该模式应该与语言无关。
I've got a server app that offers data to a number of clients over network. You can imagine the data as a huge list of strings. The data on the server may change and need to be synchronized on all clients.
I'm currently using this approach: On initial connection, a client app requests all current data (which may be a lot of bytes). Then, it subscribes to updates (addition,s changes and deletions) of any data.
This works fine unless the data are changed on the server inbetween sending the initial data list and the app subscribing to changes - in that case, the client misses a few updates and works on outdated data without knowing it.
I believe this is a very common scenario, so there should be a pattern that solves the issue. I'm using C# 4 and WCF, but the pattern should be language agnostic I believe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否了解过 Microsoft 的 .Net 同步框架。它使您可以更好地控制同步内容和方式。完全支持 WCF。它支持增量更新并将更改同步回服务器。
该 API 相当大,不仅仅涵盖数据库同步,而且还有很多文章。这应该可以帮助您开始:
Sync Framework 数据库同步简介
同步数据库
Have you had a look at Microsoft's Synchronization Framework for .Net. It gives you finer control over what gets synchronized and how. WCF is fully supported. It supports incremental updates and synchronizing changes back to the server.
The API is pretty big and covers more than just Database Synchronization but there are plenty of articles out there. This should get you started:
Introduction to Sync Framework Database Synchronization
Synchronizing Databases
我没有这样做的经验,但是...
如果每个“初始连接”都包含一个“时间戳”,并且当您订阅时,您订阅“自初始连接的时间戳”以来,那么服务器可以包含自该时间戳以来的所有更改,是吗?
关键是要包含一些客户端和服务器都同意的服务器规范时间概念。
例如,而不是
你有
I have no experience doing this, but...
If each 'initial connection' contains a 'timestamp', and when you subscribe, you subscribe 'since timestamp of initial connection' then server could include all changes since that timestamp, yes?
Key is to include some server-canonical notion of time that both client and server agree on.
e.g. instead of
you have
我只需添加另一条消息,在订阅请求之后立即向客户端发送完整更新。
或者,客户端最初可以假设该列表是空的,并且服务器发送消息以通过将它们打包成多个增量“添加”消息来在客户端上重建完整列表。
I would just add another message that sends a full update to the client immediately after the Subscribe request.
Alternatively, the client could initially assume that the list is empty and the Server sends out messages to rebuild the full list on the Client by packaging them into a number of incremental "addition" messages.
也许这篇关于数据同步的架构模式的文章会对您有所帮助。
听起来基于事件的数据同步的设计模式很接近您的需求。
Maybe this article on Architecture Patterns for Data Synchronisation will be helpful to you.
It sounds like the Design Pattern for Event-Based Data Synchronisation is close to what you need.