Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use DropWizard bundles?

Tags:

I am curious about an elusive - but potentially very powerful - DropWizard feature called Bundles. According to the docs:

A Dropwizard bundle is a reusable group of functionality, used to define blocks of an application’s behavior.

Given that DropWizard (DW) is extremely well documented, I’m shocked that this is really the only explanation on bundles. I see a few examples of them in the wild:

  • Asset Bundle
  • Cassandra Bundle

But what I don’t understand is: bundles seem to just be code packaged and distributed in JARs. So why can’t I just write “raw” (non-“bundle”-compliant) Java classes to do what I need, slap them in a JAR, then include that JAR on my build/compile classpath, ad then use them in my DW app? Of what use is a DW bundle, and when should one use them?

like image 890
smeeb Avatar asked Jul 23 '15 14:07

smeeb


People also ask

What is a bundle in Dropwizard?

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.

What is Dropwizard used for?

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 managed in Dropwizard?

Dropwizard provides the Managed interface for this. You can either have the class in question implement the #start() and/or #stop() methods, or write a wrapper class which does so. Adding a Managed instance to your application's Environment ties that object's lifecycle to that of the application's HTTP server.


1 Answers

Bundles are like addons to Dropwizard that make it very easy to add small pieces of functionality. For example, if you use the assets bundle, you can attach a UI to your API for testing purposes and it will run on the same port and is very easy to use. Another example would be the Migrations Bundle that easily ties Liquibase into Dropwizard so you can run database migrations with the same jar. This also works well since your API could be accessing some sql database which has connection parameters defined in a yml file, the migrations would be able to run on the same database.

like image 160
user3354059 Avatar answered Sep 30 '22 11:09

user3354059