在Grails中连续轮询REST服务 [英] Continuously poll a REST service in Grails

查看:110
本文介绍了在Grails中连续轮询REST服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Grails中创建一个Web应用程序,并且我想持续(每5分钟左右)使用GET轮询REST服务,该服务检索一系列消息(或者可能没有,取决于),一旦它,我的应用程序应该将检索到的数据保存为一个对象并将其存储在我的数据库中。问题是我不知道我该如何实现它(使用Quartz的cron作业?)

I am creating a web app in Grails and I would like to continuously (every 5 minutes or so) poll a REST service using GET, which retrieves a series of messages (or possibly none, it depends) and once it is donde, my application should save the retrieved data as an object and store it in my database. The problem is that I have no idea how I should implement it (with a cron job using Quartz?)

推荐答案

cron作业使用石英将很容易实现。石英插件非常易于使用(只需安装它,然后grails create-job Foo)。在任务内部,您可以使用cron表达式(或其他方式),这将导致作业根据计划执行。

A cron job using quartz would be really easy to implement. The quartz plugin is very easy to use (just install it and then "grails create-job Foo"). Inside the task, you can use a cron expression (or a number of other ways) that will cause the job to get executed based on the schedule.

取决于少数事情来说,GET表达式也很容易编写。根据您尝试访问的服务,它可能非常简单:

Depending on a few things, the GET expression is also very easy to write. Depending on the service you're trying to hit it could be as easy as:

def result = new URL("http://google.com").text
// parse result depending on what it is

这篇关于在Grails中连续轮询REST服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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