23

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:

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?

smeeb
  • 22,487
  • 41
  • 197
  • 389

3 Answers3

8

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.

user3354059
  • 382
  • 1
  • 12
  • 4
    Thanks @user3354059 (+1) - so I totally *get* that bundles are meant for reusing DW app functionality across multiple DW apps. I guess I'm just not understanding why I need to create a "bundle" vs just package the common code into a JAR, and have each of my DW apps use the classes defined in that JAR. All the examples you cited (Migrations/Liquibase/etc.) could just as well be packaged in a normal JAR - not conforming to any Bundle API - and then all of my DW apps could depend on that JAR and use its classes to accomplish DB migrations. I know I'm missing *something*, I'm just not seeing it. – smeeb Jul 23 '15 at 15:05
  • 2
    It's probably an ease of use thing. I find it a lot easier to add the few lines of code to add the bundles than to create a whole other library for the few functions you need. – user3354059 Jul 24 '15 at 16:51
  • 1
    Thanks @user3354059, I was googling for "how to create own custom bundle for dropwizard", but I didn't any tutorial that helps me to create my own bundle. I just got only one link that is your response. But still, various, things are not. I understand that we create a reusable component as DW (dropwizard) bundle, but still not clear what are the life-cycle of DW bundle, what are the interface require to implement it, can u point to some tutorial that help me to create my own DW bundle. – Hrishikesh Mishra Oct 25 '15 at 09:56
  • 2
    @smeeb I wonder if you ever found an answer to this question somewhere else, as I have the same question – allstar Dec 18 '17 at 19:39
0

Let say you work for your Platform Team in your company, and your developers use Kafka as message-bus.

Then, you can ask the dev team to add the below configuration in their DW app, and you can write the bundle to parse the broker-uris, and build the Producer Instance. With Integration with any Dependency Injection frameworks, all your have to do is @InJect the Producer Instance when you need.

kafka-broker-uris: <your kafka broker urls>

We can do the same thing using a library, and call a method that gets an broker-uri and return a producer object..

But, I believe, the main benefit comes from the Bundle knowing how to parse the configuration, and pre-builds necessary objects during the Initialize phase of DW lifecycle. Also, if you want to set a standard in your company on how the config file has to be defined, then it is good to go with a bundle.

0

DW bundles are similar to "raw" JAR in the manner that both can be used to provide reusable functionality. However, the difference lies in the additional support that DW bundles enjoy. Bundles can be made configurable i.e. they can use the DW configuration file for configuration parameters