在 Java EE 应用程序中通过消息队列对临时数据进行后台处理

发布于 2024-12-12 04:04:37 字数 543 浏览 0 评论 0原文

我正在构建一个 Java EE Web 应用程序,它还有一个 JAX-RS API,以便其他网站上的插件可以向它发送数据,将其视为一个分析服务器,它从各个客户端站点接收数据并拥有自己的管理界面人们可以在其中查看统计数据。

客户端发送的数据当前保存在数据库的临时表中;之后应该进一步处理,并保存到保存统计数据的真实表中。

之后我应该如何实现该数据的后台处理?我应该自己创建线程,还是应该使用消息队列系统(我已经研究过 RabbitMQ,它似乎很有前途,但我不确定它是否适合嵌入到 Java EE 应用程序中)

另外,我应该保存我当前数据库中的临时数据(来自用户的一大块信息,作为 JSON/XML 字符串),或者您认为保存在另一个临时数据库中更合适,例如我再次听说过像 Redis、mongodb 这样的 nosql 数据等等,但是无法决定自己是否适合做这个。

最后,如果我应该使用消息队列,请求应该由消息队列处理,还是由 JAX-RS 处理?我对 JAX-RS 的担忧是它的性能可能不如队列,正如我所说,我并不真正需要 API,我只是想获取单个 base-64 编码的字符串(包含各种统计信息)来自客户网站。

I am building a Java EE web application, which also has a JAX-RS API so that plugins at other web sites can send data to it, think of it like an analytics server which receives data from various client sites and has its own admin interface where one can view the stats.

The data that the clients send is currently saved in a temporary table in the database; and is supposed to be further processed afterwards, and saved into the real table holding the statistic data.

How should I implement the background processing of that data afterwards? Should I create threads myself, or should I use a message queue system (I have looked at RabbitMQ and it seems promising, however I'm not sure if it is appropriate for embedding in a Java EE application)

Also, should I be saving the temporary data (one chunk of information from the user, as a JSON/XML string) in my current database, or would you think that saving in another temporary database is more appropriate, for example I have again heard of nosql datas like Redis, mongodb etc., however cannot decide whether they are suitable for this.

Finally, if I should use a message queue, should the requests be handled by the message queue, or again JAX-RS? My concern with JAX-RS would be that it may not be as performant as queues and as I said, I don't really need an API, I just want to get a single base-64 encoded string (that contains various statistical info) from the client web sites.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雪碎 2024-12-19 04:04:37

这里有很多问题 :) 我将尝试按顺序回答:

  • 您将无法将 RabbitMQ 嵌入您的 JavaEE 应用程序中,因为它在 Erlang 上运行。如果您需要在 JavaEE 应用程序中嵌入消息代理,那么您更愿意考虑 ActiveMQ 或 HornetQ。
  • 如果您使用消息传递系统的持久存储功能,则无需将传入消息存储在临时数据库中。如果您传入的消息很小(KB 而不是 MB),则此方法非常适合您。
  • 使用消息系统作为传入消息的主要守护者也将为您的线程问题提供答案:在消息队列上使用 1-n 个并发消费者(即您选择的特定消息系统的并发消费者)来处理消息并将结果写入统计数据库。
  • 最后,请三思而后行,不要直接暴露您的消息传递系统,而不是在 HTTP 门面后面(在您的情况下为 JAX-RS),因为并非所有客户端都有能力使用正确的协议(如果您选择 RabbitMQ,AMQP 具有出色的交叉能力) -不过平台支持)。此外,直接公开它可能会引起安全问题。

Lots of questions here :) I'll try to answer in order:

  • You won't be able to embed RabbitMQ in your JavaEE application because it runs on Erlang. If embedding the message broker in the JavaEE application is a requirement for you, you'd rather look at ActiveMQ or HornetQ.
  • If you use the durable storage feature of a messaging system, you won't need to store the incoming messages in a temporary database. This approach would work fine for you if your incoming messages are small (KBs not MBs).
  • Using a messaging system as the main keeper of incoming messages will also provide an answer to your threads question: use 1-n concurrent consumers (ie concurrent consumers for the particular messaging system you've selected) on the message queue to process the messages and write the results in the statistics database.
  • Finally, think twice about exposing your messaging system directly instead of behind an HTTP facade (JAX-RS in your case), as not all your clients may have the capacity to speak the right protocol (if you go for RabbitMQ, AMQP has excellent cross-platform support though). Also, it might be a security concern to expose it directly.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文