best practice: running multiple services using dropwizard

1,407 views
Skip to first unread message

Shengjie Min

unread,
Dec 12, 2012, 10:39:38 AM12/12/12
to dropwiz...@googlegroups.com
Hi,

Has anyone had the situation where you have two or more services sitting in a single shard jar? Let's say I have service1, service2 they are in a single jar because they share a lot of stuff together so it doesn't make much sense to separate them into two different projects.

Given in pom.xml, I can only set up one mainclass, what's the best practice approach here? Now I am thinking to create a genericService class having a main method like this:

    public static void main(String[] args) throws Exception {
        //if arg == service1
        new Service1().run(args);
        //else if arg == service2
        new Service2().run(args);
    }

so when running the service1 or service2 individually, the command will be something like :

java -jar ${blabla}/service.jar server service1.yml service1

java -jar ${blabla}/service.jar server service2.yml service2


Any thoughts?

--
All the best,
Shengjie Min

Tatu Saloranta

unread,
Dec 12, 2012, 12:56:52 PM12/12/12
to dropwiz...@googlegroups.com
On Wed, Dec 12, 2012 at 7:39 AM, Shengjie Min <kelvi...@gmail.com> wrote:
> Hi,
>
> Has anyone had the situation where you have two or more services sitting in
> a single shard jar? Let's say I have service1, service2 they are in a single
> jar because they share a lot of stuff together so it doesn't make much sense
> to separate them into two different projects.

Would it not make sense to separate common parts as shared libraries?
That's the usual way to do it.
Shared source code is not a good way to do code reuse, generally leads
to hard to maintain and brittle code.

-+ Tatu +-

Coda Hale

unread,
Dec 12, 2012, 1:01:08 PM12/12/12
to dropwiz...@googlegroups.com
That doesn't make any sense, no.

Extract the things they have in common into a shared module and deploy two separate services.

Or combine them into the same service.

---
Coda Hale
http://codahale.com

S Ahmed

unread,
Dec 13, 2012, 9:19:04 PM12/13/12
to dropwiz...@googlegroups.com
Hope this isn't too off topic, I know you guys mentioned micro services in the past as a general design ideology etc.

But does this mean with drop wizard, each 'service' has to be run on its own and a seperate managed resource with its own startup script etc?

For example, maybe I'm confusing things, but is there a 1:1 relationship between a service and its resource class? e.g. if I am building services around a CMS product, would that mean I would build seperate services for memebership, content management, permissions, etc?

UserService with resources like /users/login users/create /users/delete etc.
ContentService /content/add /content/list content/delete content/update
...
..

Would the above (and more) all be seperate discrete jvm processes with their own startup/shutdown scripts etc?

S Ahmed

unread,
Dec 13, 2012, 9:20:20 PM12/13/12
to dropwiz...@googlegroups.com
If what I said is correct, this is in contrast to say a spring mvc application, with all of the services being bundled together in a single jvm process.

Coda Hale

unread,
Dec 14, 2012, 12:03:44 AM12/14/12
to dropwiz...@googlegroups.com
You can have as many resources in a service as you want.

---
Coda Hale
http://codahale.com



Shengjie Min

unread,
Dec 14, 2012, 5:21:39 AM12/14/12
to dropwiz...@googlegroups.com
@S Ahmed 

>UserService with resources like /users/login users/create /users/delete etc.
>ContentService /content/add /content/list content/delete content/update

in you case here, you will just need once service with multiple resources:
environment.addResource(new UserResourceImpl(configuration));
environment.addResource(new ContentResourceImpl(configuration));

as result of this, they will be bundled together in a single jvm process.

SHengjie
Reply all
Reply to author
Forward
0 new messages