分类: Java
2015-07-17 12:20:01
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.
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:
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.