如何使用Message Broker和数据库设计分布式应用程序? [英] How to design a distributed application using a Message Broker and a Database?

查看:224
本文介绍了如何使用Message Broker和数据库设计分布式应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个分布式销售点系统,有点类似于

I would like to implement an distributed Point-Of-Sale system, somewhat like the one described in Point of sale app architecture advice.

这是一个具有以下特征的分布式系统:

It is a distributed system with these charachteristics:


  • 客户端关键任务,即使网络连接或服务器发生故障,但只需几天左右,它们仍可正常工作。

  • 客户端必须易于安装。

  • 每个客户端都有自己的本地嵌入式数据库。

  • 客户端

  • 服务器用于备份,记帐,统计和向客户分发价格。

  • 服务器正在使用消息队列。

  • The clients are mission critical, they should work even if the network connection or the server fails, but just for a few days or so.
  • The clients must be easy to install.
  • Each client has it's own local embedded database.
  • The communication between the clients and the server is using a message queue.
  • The server is used for backup, bookkeeping, statistics and distribute prices to the clients.
  • The server is placed on internet.

我使用JavaDB作为数据库在Java Swing中实现客户端。

I am implementing the client in Java Swing with JavaDB as the database.

我的应用程序如何与消息代理和数据库通信?

我从未使用过消息队列和消息经纪人之前。我的想法是,应用程序从数据库读取,但写入消息代理,消息代理写入数据库并与服务器通信。或者这是一个坏主意?我应该如何解决这个问题?

I have never used Message Queues and Message Brokers before. My idea is that the application reads from the database, but writes to the message broker, and the message broker writes to the database and communicates with the server. Or is this a bad idea? How should I solve this?

除了我的嵌入式数据库,我需要找到一个消息代理,最好是用Java编写的,可以嵌入我的应用程序,安装。

So besides my embedded database, I need to find a message broker, preferably one written in Java that could be embedded in my application, for easy installation.

推荐答案

在纯技术层面,这可能是一个很好的开始点: http://java.sun.com/products/jms/tutorial/

On a pure technical level this might be a good point to start: http://java.sun.com/products/jms/tutorial/

你还应该得到一本书企业集成模式的副本它解释了所有可以使用排队系统的各种方法。

You also should absolutely get a copy of the book "Enterprise Integration Patterns" It explains all the various ways one can use queuing systems.

描述,我设想以下模式是有用的(对不起,不知道在本书中使用的术语,因为我现在没有它。自己做):

From what you describe, I envision the following patterns to be useful (sorry, don't know the terms used in the book, since I don't have it right now. Making up my own):


  • 发布订阅:服务器将发布消息(例如价格信息更新),这些消息将发送给订阅此类信息的所有客户端。你必须覆盖的一个重要的情况是问题,将发生什么,当你的客户端在这样的广播期间断开连接。

  • publish subscribe: The server would publish messages (e.g. updates to price information) which get delivered to all clients subscribing to that kind of information. One important case you'll have to cover is the question, what is going to happen, when your client is disconnected during such a broadcast. You have to make sure it doesn't miss any message, or has a way to catch up again.

消防和忘记:一个通讯伙伴(例如:客户端)将发送消息,而不需要任何类型的响应。排队系统将负责最终交付。

fire and forget: One communication partner (e.g. the client) will sent a message, without expecting any kind of response. The queuing system will take care of eventual delivery. This could be used for submitting orders and the like.

回拨:这就像两个或更多的消防和忘记消息在相反的方向。其中后续呼叫将具有id以便将消息标记为对先前接收的某个消息的响应。这是有用的,当你提交订单,但需要某种回答。当然,答案可能在一天后到达,因此您需要一个未完成订单的列表,这可能也应该是用户或列表支持人员可见的。当发送多个回复时,您必须处理消息不按顺序到达的情况。如果可能的话,一个很好的方法来处理这一点是包括每个以下消息中的早期消息的所有信息。

call back: This is like two or more fire and forget messages in opposite directions. Where subsequent calls will have an id in order to tag the message as a response to a certain message received before. This is usefull when you submit orders, but need some kind of answer. Of course the answer might arrive a day later, so you'll need a list of outstanding orders, which probably should also be visible to the user, or at list support personal. When sending multiple replies, you must handle the case of messages arriving out of order. When possible a nice way to handle this is to include all the information of earlier messages in each following message. This way you can simply discard older messages.

所以通信可以这样工作:
- 服务器偶尔向所有客户端发送更新。该消息可能应包含某种版本信息,因此客户端可以确保,它们具有所有消息。
- 定期(或者从服务器接收没有更新一段时间或...),客户端从服务器请求特殊更新,以确保它具有所有当前信息。上面提到的版本信息可以用于识别缺少的信息
- 客户端接收消息并将内容存储在本地db
- 客户端从db读取以便向用户提供信息
- 客户端向服务器提交订单或发生什么事,可能会收到不同步的答复

So communication could work like this: - server occasionally sends updates to all clients. The message probably should contain some kind of version information, so the clients can make sure, they have all the messages. - on a regular basis (or aftger receiving no update from the server for some time or ...) the client requests a special update from the server in order to ensure that it has all the current information. The version information mentioned above can be used to identify the missing information - clients receive the message and store the content in the local db - client reads from db in order to present information to the user - client submits orders or what ever to the server, possibly receiving an out of sync answer

一些一般建议:

随着排队,你处在并发地狱的中间。所以得到创造性的所有的东西,可以去错误。例子是
- 消息不按顺序到达
- 接收者在发送时不可用(这是首先使用消息传递的原因)
- 接收者不可用和永远不会回到在线。消息服务器有保证交付的选项。这意味着他们必须存储消息,直到实际送达。如果客户端永远不会在线,邮件将永远保留,填满存储位置

With queuing you are in the middle of concurrency hell. So get creative about all the things that can go 'wrong'. Examples are - messages arriving out of order - receiver not available at time of sending (well that is the reason for using messaging in the first place) - receiver not being available and never going back online. Messaging server have options to guarantee delivery. This means they have to store the message until the actually deliver it. If clients never come back online, messages will stay for ever, filling up the storage place

确保所有邮件处理与您的应用程序的其余部分完全分离测试。

Make sure all the messaging handling is cleanly separated from the rest of your application for easy testing.

考虑升级服务器和客户端的过程,特别是当消息格式改变时。您必须在同一时间点进行升级,并在两者之间停机,否则您的服务器必须能够在一段时间内处理新旧的邮件格式。

Think through the process of upgrading server and clients especially when the message formats change. You either have to upgrade all at the same point of time with some downtime in between, or your server must be able to process old and new message format for some time.

这篇关于如何使用Message Broker和数据库设计分布式应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆