使用消息队列的Web应用程序的体系结构

编程入门 行业动态 更新时间:2024-10-26 23:41:00
本文介绍了使用消息队列的Web应用程序的体系结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个Java Web应用程序,该应用程序通过数据库表(EmailQueue)使用某种形式的自定义消息队列来对电子邮件的传递进行排队.该应用程序已部署在Tomcat上,并使用 Quartz 作业来轮询EmailQueue表中要发送的新条目. /p>

我现在需要添加一些其他类型的作业和消息(通知,短信等)的排队,因此正在考虑使用适当的消息队列( RabbitMQ , ActiveMQ 等),而不是数据库.这是由很少 文章,该论据认为不应将数据库用作队列.

但是,我还没有完全了解整个生态系统,因此希望您能提供一些指导.具体来说:

  • 在Web应用程序的上下文中,消息队列代理通常像数据库一样作为自己的进程运行吗?在服务器重新启动的情况下,我需要消息是持久的.
  • 消息队列使用者应该部署为Tomcat中的servlet还是独立的Java应用程序?我对这一切的可管理性(例如,启动/停止实例,配置,监视)特别感兴趣.相关和电子邮件线程.

解决方案

1.在Web应用程序的上下文中,消息队列代理通常像数据库一样以其自己的进程运行吗?在服务器重新启动的情况下,我需要消息是持久的.

消息队列代理通常作为其自己的进程运行.使用RabbitMQ,您的生产者可以将消息定义为持久的.

2.消息队列使用者应该在Tomcat中部署为servlet还是在独立的Java应用程序中?我对所有内容的可管理性(即启动/停止实例,配置,监视)以及相关问题和电子邮件线程特别感兴趣.

关于类似主题的问题在这里,我最终将使用者部署为Tomcat应用程序,这确实为我提供了我一直在寻找的可管理性.这使我可以编写servlet来监视和管理队列.

此解决方案还可以实现可伸缩性,这对于消息传递&排队.通过拍摄运行Tomcat的服务器的快照(我正在使用Amazon EC2实例)并将该快照部署到新实例上,我还能够轻松地动态扩展使用方的数量.我已将Tomcat配置为作为服务自动启动,以便在启动新实例时,将部署使用者.war文件并自动开始使用.

但是,正如我在问题中所讨论的那样,请谨慎对待线程.我最初遇到了停止Tomcat的问题.

但是,您也可以使用JMX作为独立的Java应用程序来实现与消费者之间的可管理性.使用JConsole,您可以在运行时远程访问Java应用程序并查询/更新参数.许多监视程序(例如Zabbix)都可以使用JMX连接到应用程序.

如果您喜欢Web开发和构建自己的Web应用程序,那么我会选择Tomcat.希望有帮助.

I have a java web application which uses some form of custom message queuing via a database table (EmailQueue) to queue delivery of emails. The application is deployed on Tomcat and uses Quartz jobs which polls for new entries in the EmailQueue table to send.

I now need to add queuing of a few other types of jobs and messages (notifications, sms, etc.) and am therefore looking into using a proper message queue (RabbitMQ, ActiveMQ, etc.) instead of the database. This is motivated by a few articles on the matter which argue a database should not be used as a queue.

I haven't completely gotten my mind wrapped around the whole ecosystem however and would appreciate some guidance. Specifically:

  • In the context of web applications, does the message queue broker usually run as its own process, like the database does? I need the messages to be persistent in case of server restarts.
  • Should the message queue consumers be deployed as servlets in Tomcat or as standalone java applications? I'm especially interested in the manageability of it all (i.e. start/stop instances, configuration, monitoring) Related question and email thread.

解决方案

1. In the context of web applications, does the message queue broker usually run as its own process, like the database does? I need the messages to be persistent in case of server restarts.

The message queue broker typically runs as its own process. With RabbitMQ, your producers can define the messages to be persistent.

2. Should the message queue consumers be deployed as servlets in Tomcat or as standalone java applications? I'm especially interested in the manageability of it all (i.e. start/stop instances, configuration, monitoring) Related question and email thread.

Regarding my question on a similar topic here, I ultimately deployed my consumers as Tomcat applications, which did provide me with the manageability that I too was looking for. This allowed me to write servlets for monitoring and managing the queues.

This solution works for scalability, also, which is important with messaging & queuing. I was also able to easily scale the number of consumers on the fly by taking a snapshot of the server running Tomcat (I was using Amazon EC2 instances) and deploying that snapshot onto a new instance. I had configured Tomcat to start automatically as a service so that when the new instance started, the consumer .war files would deploy and automatically start consuming.

Be careful with the threading, however, as discussed in my question. I had initially run into problems with stopping Tomcat.

You can also achieve manageability with consumers as standalone Java applications using JMX, however. Using JConsole, you can remote into your Java applications and query/update parameters during runtime. Many monitoring programs, such as Zabbix, can connect to applications using JMX.

If you enjoy web development and building your own web applications, I would go the Tomcat route. Hope that helps.

更多推荐

使用消息队列的Web应用程序的体系结构

本文发布于:2023-11-11 16:44:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579015.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   体系结构   应用程序   消息   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!