Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long request processing with DropWizard

I have a simple DropWizard service and I'd like a REST API to start a long running processing task - both CPU and I/O bound. REST call will not wait for task completion, notification will happen by polling/long polling/web socket.

For now, I'd prefer if I can do this in Dropwizard and keep everything in single deployable JAR. What are my options?

UPDATE: I am interested in what my options are regarding running long running tasks in Dropwizard, deployed as single jar without external dependencies. Just spawn a new thread? Assuming there are just few such requests it would probably work but there should be better options.

like image 876
bh213 Avatar asked Sep 05 '14 16:09

bh213


People also ask

Does Dropwizard use Jetty?

Because you can't be a web application without HTTP, Dropwizard uses the Jetty HTTP library to embed an incredibly tuned HTTP server directly into your project.

Does Dropwizard use Log4j?

Dropwizard uses Logback for its logging backend. It provides an slf4j implementation, and even routes all java. util. logging , Log4j, and Apache Commons Logging usage through Logback.

What is a Dropwizard service?

Dropwizard is an open-source Java framework used for the fast development of high-performance RESTful web services. It gathers some popular libraries to create the light-weight package. The main libraries that it uses are Jetty, Jersey, Jackson, JUnit, and Guava. Furthermore, it uses its own library called Metrics.

What is a Dropwizard bundle?

A Dropwizard Bundle is a reusable group of functionality (sometimes provided by the Dropwizard project itself), used to define blocks of an application's behavior.


1 Answers

You probably want to use a managed resource:

https://dropwizard.io/en/stable/manual/core.html#managed-objects

to setup a thread pool. Then, your initial request could push a message onto a queue. Your thread pool can pull messages off the queue and process them asynchronously.

You could maybe provide an additional endpoint so that clients can obtain the current state of the asynchronous process.

like image 89
Daniel Scott Avatar answered Oct 04 '22 09:10

Daniel Scott