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

查看:265
本文介绍了如何设计一个使用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.

正是有了这些charachteristics分布式系统:

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.

我实施的Java Swing客户端可直接用于JavaDB作为数据库。

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

如何应我的应用程序与Message Broker和数据库通信?

我从来没有使用消息队列和消息代理。我的想法是,应用程序从数据库中读取,而是写入到消息代理,以及所述消息代理写入数据库并与服务器进行通信。或者,这是一个坏主意?我应该如何解决这个问题?

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编写的消息代理,preferably一个可以被嵌入到我的应用程序,以方便安装。

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.

所以通信可以工作是这样的:
- 服务器偶尔更新发送到所有客户端。该消息或许应该包含某种版本的信息,因此客户可以确保,他们有各种各样的消息。
- 定期(或aftger从所述服务器接收无更新一段时间或...)客户端从服务器,以确保其具有所有的当前信息请求一个特殊的更新。上述的版本信息,可以用于识别丢失的信息
- 客户收到的消息,并存储在本地数据库内容
- 客户端从数据库中读取顺序为present信息给用户
- 客户端提交订单或什么都到服务器,可能收到一个不同步的答案

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天全站免登陆