Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiscoveryClient API comments #19

Open
aantoniadis opened this issue Jan 10, 2017 · 9 comments
Open

DiscoveryClient API comments #19

aantoniadis opened this issue Jan 10, 2017 · 9 comments

Comments

@aantoniadis
Copy link

aantoniadis commented Jan 10, 2017

I have been using the library recently and I have a couple of comments regarding the API
that might worth taken into consideration.
io.dropwizard.discovery.client.DiscoveryClient exposes the following methods

/**
 * Return the running instances for the service.
 * 
 * @return Collection of service instances
 */
public Collection<ServiceInstance<T>> getInstances(
        @Nonnull final String serviceName) throws Exception {
    return discovery.queryForInstances(serviceName);
}

/**
 * Return a cached list of the running instances for the service.
 * 
 * @return Collection of service instances
 */
public Collection<ServiceInstance<T>> getInstances() {
    return cache.getInstances();
}

/**
 * Return an instance of this service.
 * 
 * @return ServiceInstance
 * @throws Exception
 */
public ServiceInstance<T> getInstance() throws Exception {
    return provider.getInstance();
}

My comment is that it is not intuitive whether a call on a method will return results from the cache or not. Maybe if we used different names for each case it would make the intention of each method much clearer.

Also, since the DiscoveryClient client is create by DiscoveryClient.newDiscoveryClient where the serviceName is passed. Why would somebody call DiscoveryClient#Collection<ServiceInstance<T>> getInstances(@Nonnull final String serviceName)?
From the factory API, I would expect the discoveryClient to find 1 type of service.

@jplock what do you think?

@jplock
Copy link
Member

jplock commented Jan 10, 2017

Those were mostly exposed as helper methods to access ZK. Since I initially created this module, I've never actually used it in production, so if there are improvements or cleanups we can make, I'd be all for that.

@aantoniadis
Copy link
Author

aantoniadis commented Jan 10, 2017

@jplock So how is the DiscoveryClient supposed to be used by the services?
I would expect it to be used to retrieve the location of required service and pass it to an httpClient.
Maybe we should include such an example in the README.md.

If so, I believe that is would be useful to create a client that does this discovery (and possible retries) under the hood and provide a fluent interface (something like https://github.com/Netflix/ribbon).

@jplock
Copy link
Member

jplock commented Feb 26, 2017

@aantoniadis I used Ribbon in my dropwizard-consul implementation I'm maintaining at https://github.com/smoketurner/dropwizard-consul/tree/master/consul-ribbon

@aantoniadis
Copy link
Author

@jplock any plans to merge dropwizard-cosul with the current project?

@jplock
Copy link
Member

jplock commented Mar 6, 2017

@aantoniadis probably not

@sliu2013
Copy link

sliu2013 commented Aug 23, 2018

@jplock Just want to ensure I understand the above comment correctly....
So this repo "dropwizard-discovery" is mainly for doing service registration to zookeeper?!
As for service discovery client, you recommend to use "dropwizard-consul" instead? Or maybe apache curator?

@jplock
Copy link
Member

jplock commented Aug 23, 2018

This library will register a service with ZK and includes a client to get a host and port from ZK if you want to talk to another service. This library doesn’t include a load balancer implementation like dropwizard-consul does.

@sliu2013
Copy link

This DiscoveryClient is the client that I can use to get host/port from ZK, right?

@jplock
Copy link
Member

jplock commented Aug 24, 2018

@sliu2013 correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants