Multiple Jersey clients with different configurations

260 views
Skip to first unread message

Michael McCarthy

unread,
Oct 30, 2013, 1:55:55 PM10/30/13
to dropwiz...@googlegroups.com
Hi there,

We have the situation where we share a Jersey client within our DW application, and make calls to a number of different remote services. Some of these services support gzip, some don't. Some are slow and require a larger timeout, and some don't. Actually, it's the same remote service that doesn't support gzip and is slow :)

At the moment we are catering for the lowest common denominator but this seems like the wrong approach as we are losing out on the benefits we get from talking to the less rubbish remote services. I would be interested to know how other people have approached the same problem - do you use a single client or multiple clients (if that is even possible?).

Thanks!


Graham O'Regan

unread,
Oct 30, 2013, 2:30:27 PM10/30/13
to dropwiz...@googlegroups.com
We use multiple clients in our services rather than sharing one, we needed to add different basic auth (over SSL) credentials for different services so we needed to add different filters to each one.

Using multiple clients is straightforard, in 0.6.2 you need to add new fields to your configuration class, one for each client you want to setup;


private com.yammer.dropwizard.client.JerseyClientConfiguration slow;
private com.yammer.dropwizard.client.JerseyClientConfiguration fast;


// getters()

Then configure the clients in your service;

Client slowClient = new JerseyClientBuilder().using(config.getSlow()).using(environment).build();

And in your configuration file;

slow:
    timeout: 2000ms
fast:
    timeout: 250ms

and repeat the process for each one.

hth,

Graham

I haven’t tried in 0.7.0 but I wouldn’t imagine that much has changed beyond the package names


--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Michael McCarthy

unread,
Nov 5, 2013, 10:31:24 AM11/5/13
to dropwiz...@googlegroups.com
Brilliant, that worked perfectly. Thanks very much.
Reply all
Reply to author
Forward
0 new messages