简体   繁体   English

Java客户端-服务器-将文件分发到多个服务器

[英]Java Client-Server - Distributing Files to multiple servers

I want to write a Java Client/Server application which should do the following: 我想编写一个Java客户端/服务器应用程序,该应用程序应执行以下操作:

  • Client connects to to one of two servers 客户端连接到两个服务器之一
  • Server sends a text file or its content to the client 服务器将文本文件或其内容发送到客户端
  • User edits the file 用户编辑文件
  • Client sends the file back to both servers simultaneously and reliably 客户端将文件同时可靠地发送回两台服务器
  • Client closes the application 客户关闭应用程序

Bonus: One of these servers might be down at the time of the transmission, so it needs to receive the file on startup. 奖励:这些服务器之一在传输时可能已关闭,因此它需要在启动时接收文件。

What architecture or framework would be good and lightweight to enable this? 哪种架构或框架将是好的且轻量级的以实现这一目标? Is JGroups a good start? JGroups是一个好的开始吗?

edit: I have to assume the following minimal network: 编辑:我必须假设以下最小网络:

  • One or more clients start the application but must not be allowed to edit the file at the same time. 一个或多个客户端启动该应用程序,但不允许同时编辑该文件。
  • There are one or more servers, of which at least one is always active (which one is sort of random) 有一个或多个服务器,其中至少有一个始终处于活动状态(这是随机的)
  • The client has a .xml file with all server addresses 客户端有一个带有所有服务器地址的.xml文件

A JMS framework (ActiveMQ) can solve your problem using a queue and a topic: JMS框架(ActiveMQ)可以使用队列和主题来解决您的问题:

  • client posts a message on a queue where both server listen, asking for the file 客户端在两个服务器都侦听的队列上发布一条消息,询问文件
  • only one server receives this requests and sends the file to the client 只有一台服务器接收此请求,并将文件发送给客户端
  • client edits the file 客户端编辑文件
  • client sends the edited file on a DURABLE topic where both servers are subscribed 客户端将在两个服务器都已订阅的DURABLE主题上发送编辑的文件

Using a durable topic is important so offline subscribers (your servers) get the file once they reconnect. 使用持久主题很重要,因此离线订户(您的服务器)在重新连接后即可获取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM