Dropwizard作为非阻塞任务执行组件

时间:2014-11-09 18:14:56

标签: java dropwizard

我正在评估dropwizard我们生产系统的关键任务组件。

我需要实现的是一个具有RESTful支持的命令行工具(几乎不需要提供REST API,我主要需要与B2B的外部API系统进行通信),记录依赖注入和一些非阻塞I / O操作以获得最佳性能。

我的问题是,是否有人具有为生产系统做好准备的特定框架的经验以及轻量级非阻塞操作的某些替代解决方案(类似于Python上的Celery)

最后,Dropwizard是否支持java 1.8?

非常感谢您提前提供的帮助

1 个答案:

答案 0 :(得分:0)

dropwizard-sundial可让您在dropwizard中安排作业。 github自述文件有更多样本,但这里有一个快速潜行高峰:

@CronTrigger(cron = "0/5 * * * * ?")
public class SampleJob extends org.knowm.sundial.Job {
  @Override
  public void doRun() throws JobInterruptException {
    // Do something interesting...
  }
}

它的作用是在初始化dropwizard应用程序时,日食将会进入并启动其调度程序。然后,您可以通过yaml,tasks,xml中的包配置任务。它注册的管理任务也可用于管理作业(创建/触发/等)。

有一点需要注意的是,dropwizard-sundial包本身包含一组dropwizard-core和dropwizard-util。您很可能会发现它与导致NoClassDefExceptionNoMethodFoundException的版本冲突。我的解决方案是从dropwizard-sundial中排除并使用你自己的。

    <dependency>
        <groupId>org.knowm</groupId>
        <artifactId>dropwizard-sundial</artifactId>
        <version>1.0.0.0</version>
        <exclusions>
            <exclusion>
                <groupId>io.dropwizard</groupId>
                <artifactId>dropwizard-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>io.dropwizard</groupId>
                <artifactId>dropwizard-util</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-server</artifactId>
            </exclusion>
        </exclusions>
    </dependency>