如何在Spring 3.0中进行后台计算? [英] how to do background computing in Spring 3.0?

查看:271
本文介绍了如何在Spring 3.0中进行后台计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在spring应用程序中,我想做一些背景计算。我的任务是保存一个实体(比方说GPS坐标),然后我想查询一个Web服务以获得所有坐标之间的距离并将它们存储在数据库中供以后使用。存储实体后,有可能无法连接到用于计算距离的Web服务。

In a spring application I want do some background computing. The task is that I save an entity( lets say a GPS coordinate) and then I want to query a web service to get distance between all the coordinates and store them in the db for later use. There is a possibility that after storing the entity, connection cannot be made to the web service which will be used for calculation of the distances.

我认为这可以实现在系统中引入一个工作(有点像cron工作)。一旦我们想要在后台发生一些事情,我们就把它放在一个工作队列中。队列将尝试执行它接收的第一个作业,作业将转到并连接到Web服务,如果由于某种原因它失败,它将保留在队列中并告诉队列它失败了。然后,队列可以在指定的重试时间后执行。当它成功完成作业时,它将从作业队列中取出。

I think that this can be accomplished with introducing a job in the system (some thing like a cron job). Once we want some thing to happen in the background we put it in a job queue. The queue will try to execute the first job it receives, A job will go and connect to the web service, if for some reason it fails, it stays in the queue and tells the queue that it failed. The queue can then execute after a specified time for retry.. When it's successfully a job complete it is taken out of the job queue.

我很清楚要求,但我不确定使用哪种技术。 JMX,JMS,Spring任务调度程序,Spring集成,混合/匹配或全部。

I am clear on the requirements, but I am not sure which technology to use. JMX, JMS, Spring Task Scheduler, Spring Integration, mix/match or all.

这类似于如何在spring webapp中创建后台进程?但不完全

编辑
让我们再加一点吧。还可以为每个CSV文件批量添加这些GPS坐标(通过CSV文件),每个条目将在文件中处理(顺序将是先到先服务文件和每个条目)。删除案例可以更简单,因为预计不会删除任何内容(但可以在以后使用deatl)

Edit Let's add to it a bit further. There is also a possibility of additions of those GPS coordinates in bulk (via a CSV file) for each CSV file every entry will be processed in file (the order will be for first come first serve file and for each entry). Deletions case can be simpler as nothing is expected to be deleted (but can be deatl with later)

推荐答案

如果您仅需要异步执行,然后 duffymo 建议的JMS方法绝对是一个很好的解决方案(消息传递是有保证的,它是容错的,交易等)。但是,如果失败,将回滚邮件并立即 传递邮件,除非您配置重新传递延迟重新传递限制。但是虽然一些JMS提供商确实提供了这样的功能(例如MQ,WebLogic,JBoss),但这不是AFAIK的标准事物(例如,GlassFish OpenMQ不提供此功能)。你需要考虑到这一点。

If you "only" need asynchronous execution, then the JMS approach suggested by duffymo is definitely a good solution (message delivery is guaranteed, it's fault-tolerant, transactional, etc). However, in case of failure, messages will be rolled back and immediately delivered, unless you configure a Redelivery Delay and a Redelivery limit. But while some JMS providers do offer such features (e.g. MQ, WebLogic, JBoss), this is not a standard thing AFAIK (for example, GlassFish OpenMQ doesn't offer this). You need to take this into account.

另一种方法是使用调度程序(特别是如果你还想延迟或安排作业执行) - 我就是在这里思考Quartz - 并在失败时重新安排工作(这完全由Quartz支持)。而Spring也提供了很好的Quartz集成。

Another approach would be to use a scheduler (especially if you also want to delay or schedule the jobs execution) - and I'm thinking to Quartz here - and to reschedule jobs on failure (this is fully supported by Quartz). And Spring also provides nice integration of Quartz.

这篇关于如何在Spring 3.0中进行后台计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆