Java JMS/消息队列的实际使用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1035949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:32:25  来源:igfitidea点击:

Real world use of JMS/message queues?

javajmsmessage-queue

提问by nos

I was just reading abit about JMS and Apache ActiveMQ. And was wondering what real world use have people here used JMS or similar message queue technologies for ?

我只是在阅读有关 JMS 和 Apache ActiveMQ 的知识。并且想知道这里的人们使用 JMS 或类似的消息队列技术在现实世界中有什么用途?

采纳答案by Jon

JMS (ActiveMQ is a JMS broker implementation) can be used as a mechanism to allow asynchronous request processing. You may wish to do this because the request take a long time to complete or because several parties may be interested in the actual request. Another reason for using it is to allow multiple clients (potentially written in different languages) to access information via JMS. ActiveMQ is a good example here because you can use the STOMP protocol to allow access from a C#/Java/Ruby client.

JMS(ActiveMQ 是 JMS 代理实现)可用作允许异步请求处理的机制。您可能希望这样做,因为请求需要很长时间才能完成,或者因为多个方可能对实际请求感兴趣。使用它的另一个原因是允许多个客户端(可能用不同语言编写)通过 JMS 访问信息。ActiveMQ 是一个很好的例子,因为您可以使用 STOMP 协议来允许从 C#/Java/Ruby 客户端进行访问。

A real world example is that of a web application that is used to place an order for a particular customer. As part of placing that order (and storing it in a database) you may wish to carry a number of additional tasks:

一个真实世界的示例是用于为特定客户下订单的 Web 应用程序。作为下订单(并将其存储在数据库中)的一部分,您可能希望执行一些额外的任务:

  • Store the order in some sort of third party back-end system (such as SAP)
  • Send an email to the customer to inform them their order has been placed
  • 将订单存储在某种第三方后端系统(例如 SAP)中
  • 向客户发送电子邮件,通知他们已下订单

To do this your application code would publish a message onto a JMS queue which includes an order id. One part of your application listening to the queue may respond to the event by taking the orderId, looking the order up in the database and then place that order with another third party system. Another part of your application may be responsible for taking the orderId and sending a confirmation email to the customer.

为此,您的应用程序代码将向包含订单 ID 的 JMS 队列发布一条消息。侦听队列的应用程序的一部分可能会通过获取 orderId 来响应事件,在数据库中查找订单,然后向另一个第三方系统下订单。应用程序的另一部分可能负责获取 orderId 并向客户发送确认电子邮件。

回答by duffymo

Use them all the time to process long-running operations asynchronously. A web user won't want to wait for more than 5 seconds for a request to process. If you have one that runs longer than that, one design is to submit the request to a queue and immediately send back a URL that the user can check to see when the job is finished.

一直使用它们来异步处理长时间运行的操作。Web 用户不希望等待超过 5 秒的时间来处理请求。如果您有一个运行时间比这更长的时间,一种设计是将请求提交到队列并立即发回一个 URL,用户可以检查该 URL 以查看作业何时完成。

Publish/subscribe is another good technique for decoupling senders from many receivers. It's a flexible architecture, because subscribers can come and go as needed.

发布/订阅是另一种将发送者与许多接收者分离的好技术。这是一个灵活的架构,因为订阅者可以根据需要来来去去。

回答by pugmarx

Distributed (a)synchronous computing.
A real world example could be an application-wide notification framework, which sends mails to the stakeholders at various points during the course of application usage. So the application would act as a Producerby create a Messageobject, putting it on a particular Queue, and moving forward.
There would be a set of Consumers who would subscribe to the Queuein question, and would take care handling the Messagesent across. Note that during the course of this transaction, the Producers are decoupled from the logic of how a given Messagewould be handled.
Messaging frameworks (ActiveMQ and the likes) act as a backbone to facilitate such Messagetransactions by providing MessageBrokers.

分布式(a)同步计算。
一个真实世界的例子可能是一个应用程序范围的通知框架,它在应用程序使用过程中的不同时间点向利益相关者发送邮件。因此,该应用程序将Producer通过创建一个Message对象,将其放在特定的 上Queue并继续前进。
将有一组Consumers 订阅有Queue问题的内容,并会小心处理Message发送的内容。请注意,在此事务的过程中,Producers 与如何Message处理给定的逻辑分离。
消息传递框架(ActiveMQ 等)充当主干,Message通过提供MessageBrokers来促进此类事务。

回答by bluegene

We have used messaging to generate online Quotes

我们已经使用消息来生成在线报价

回答by mikesomeone

I've had so many amazing uses for JMS:

我对 JMS 有很多惊人的用途:

  • Web chat communication for customer service.

  • Debug logging on the backend. All app servers broadcasted debug messages at various levels. A JMS client could then be launched to watch for debug messages. Sure I could've used something like syslog, but this gave me all sorts of ways to filter the output based on contextual information (e.q. by app server name, api call, log level, userid, message type, etc...). I also colorized the output.

  • Debug logging to file. Same as above, only specific pieces were pulled out using filters, and logged to file for general logging.

  • Alerting. Again, a similar setup to the above logging, watching for specific errors, and alerting people via various means (email, text message, IM, Growl pop-up...)

  • Dynamically configuring and controlling software clusters. Each app server would broadcast a "configure me" message, then a configuration daemon that would respond with a message containing all kinds of config info. Later, if all the app servers needed their configurations changed at once, it could be done from the config daemon.

  • And the usual - queued transactions for delayed activity such as billing, order processing, provisioning, email generation...

  • 用于客户服务的网络聊天通信。

  • 在后端调试日志记录。所有应用服务器都在不同级别广播调试消息。然后可以启动 JMS 客户端以监视调试消息。当然我可以使用类似syslog 的东西,但这给了我各种方法来根据上下文信息过滤输出(按应用服务器名称、api 调用、日志级别、用户 ID、消息类型等...)。我还对输出进行了着色。

  • 调试日志记录到文件。与上述相同,仅使用过滤器提取特定部分,并将其记录到文件中以进行一般记录。

  • 警报。同样,与上述日志类似的设置,监视特定错误,并通过各种方式(电子邮件、短信、IM、Growl 弹出窗口...)提醒人们

  • 动态配置和控制软件集群。每个应用程序服务器都会广播一条“配置我”消息,然后是一个配置守护进程,它将以包含各种配置信息的消息进行响应。稍后,如果所有应用程序服务器都需要立即更改其配置,则可以从配置守护程序中完成。

  • 以及通常的排队交易以延迟活动,例如计费,订单处理,供应,电子邮件生成......

It's great anywhere you want to guarantee delivery of messages asynchronously.

在您想要保证异步传递消息的任何地方,它都很棒。

回答by Kevin Williams

We use it to initiate asynchronous processing that we don't want to interrupt or conflict with an existing transaction.

我们使用它来启动我们不想中断或与现有事务冲突的异步处理。

For example, say you've got an expensive and very important piece of logic like "buy stuff", an important part of buy stuff would be 'notify stuff store'. We make the notify call asynchronous so that whatever logic/processing that is involved in the notify call doesn't block or contend with resources with the buy business logic. End result, buy completes, user is happy, we get our money and because the queue is guaranteed delivery the store gets notified as soon as it opens or as soon as there's a new item in the queue.

例如,假设您有一个昂贵且非常重要的逻辑,例如“购买东西”,购买东西的一个重要部分将是“通知商店”。我们使通知调用异步,以便通知调用中涉及的任何逻辑/处理都不会阻塞或与购买业务逻辑的资源争用。最终结果,购买完成,用户很高兴,我们得到了我们的钱,因为队列保证交付,商店一开张或队列中有新项目就会收到通知。

回答by paradisontheitroad

I have seen JMS used in different commercial and academic projects. JMS can easily come into your picture, whenever you want to have a totally decoupled distributed systems. Generally speaking, when you need to send your request from one node, and someone in your network takes care of it without/with giving the sender any information about the receiver.

我见过 JMS 用于不同的商业和学术项目。无论何时您想要一个完全解耦的分布式系统,JMS 都可以轻松进入您的视野。一般来说,当您需要从一个节点发送您的请求时,您网络中的某个人会在不/不向发送者提供有关接收者的任何信息的情况下处理它。

In my case, I have used JMS in developing a message-oriented middleware (MOM) in my thesis, where specific types of object-oriented objects are generated in one side as your request, and compiled and executed on the other side as your response.

就我而言,我在论文中使用 JMS 开发了一个面向消息的中间件 (MOM),其中特定类型的面向对象对象在一侧作为您的请求生成,并在另一侧作为您的响应进行编译和执行.

回答by RichardOD

I've used it to send intraday trades between different fund management systems. If you want to learn more about what a great technology messaging is, I can thoroughly recommend the book "Enterprise Integration Patterns". There are some JMS examples for things like request/reply and publish/subscribe.

我用它在不同的基金管理系统之间发送日内交易。如果您想更多地了解什么是伟大的技术消息传递,我可以彻底推荐“企业集成模式”一书。有一些 JMS 示例用于请求/回复和发布/订阅等。

Messaging is an excellent tool for integration.

消息传递是一种出色的集成工具。

回答by Rob Davies

Apache Camelused in conjunction with ActiveMQ is great way to do Enterprise Integration Patterns

Apache Camel与 ActiveMQ 结合使用是实现企业集成模式的好方法

回答by roundrobin

We are using JMS for communication with systems in a huge number of remote sites over unreliable networks. The loose coupling in combination with reliable messaging produces a stable system landscape: Each message will be sent as soon it is technically possible, bigger problems in network will not have influence on the whole system landscape...

我们正在使用 JMS 通过不可靠的网络与大量远程站点中的系统进行通信。松散耦合与可靠消息的结合产生了稳定的系统格局:每条消息都会在技术上尽可能快地发送,网络中更大的问题不会影响整个系统格局......