如何在grails应用程序中创建作业和队列 [英] How to create a job and queue in a grails application
问题描述
我有一个Grails应用程序,用户上传文件,我的应用程序用上传的文件做各种事情。其中一些任务需要很长时间,因此用户必须等待才能看到下一页。
我想要更改此行为,以便用户上传文件,然后立即看到下一页。上传的文件将在后台排队。稍后,我想从队列中提取文件,并按收到的顺序处理它们。
grails应用程序有哪些选项可用来完成此操作?这将是最好的,如果我可以指向一个教程
基于原始问题 Job
和 Queue
,您可以通过多种方式在您的grails应用程序中使用消息侦听器。其中一些是:
- Grails中的JMS插件:使用ActiveMQ。
- Active MQ插件Grails
- (by Pivotal):Out of该盒子。
- 还为grails 。 >
当作业执行
时,一致的插件可以是:
现在谈谈您的问题的目标,您还可以实现文档上传功能异步如果g rails版本低于2.3 ,或者您可以使用提供的异步支持在Grails 2.3版本中,它坚持即丢即用策略。用户触发文档上传请求并忘记它,并在任务完成时得到通知。
如果您认识到常用的基于JS的框架中的Promises(for例如:AngularJS),那么在grails 2.3中使用Promise对你来说将是一个更简单的方法。
I have a grails application in which the user uploads a document and my application does various things with the uploaded file. Some of these tasks take a long time so the user has to wait to see the next page.
I want to change this behavior such that the user uploads the file and then immediately sees the next page. In the background the uploaded file will be queued. Later I want to pick-up files from the queue and process them in the order they were received.
What are some options available to a grails application to accomplish this? It'll be best if I can be pointed to a tutorial
Based on the original question about Job
and Queue
, there are various ways you can have a message listener in your grails application. Some of them are:
- JMS plugin in Grails: Uses ActiveMQ.
- Active MQ plugin in Grails
- RabbitMQ (by Pivotal): Out of the box.
- Also RabbitMQ plugin for grails.
When job execution
is concerned, the unanimous plugins would be either:
Now coming to the objective of your question, you can also achieve the document upload functionality asynchronously if grails version is below 2.3 or you can leverage the Async support provided in Grails version 2.3 which sticks to "fire-and-forget" policy. User fires the document upload request and forgets about it, and gets notified when the task gets completed.
If you are cognizant of "Promises" in common JS based frameworks (for eg: AngularJS) then using Promises in grails 2.3 will be an easier approach for you.
这篇关于如何在grails应用程序中创建作业和队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!