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

Filter services by tag in ConsulDiscoveryClient #18

Closed
avthart opened this issue Apr 3, 2015 · 6 comments
Closed

Filter services by tag in ConsulDiscoveryClient #18

avthart opened this issue Apr 3, 2015 · 6 comments
Assignees
Milestone

Comments

@avthart
Copy link

avthart commented Apr 3, 2015

It would be nice to filter services by tag using the ConsulDiscoveryClient. Sometimes you only want some specific services in your application.

@outcomes-scott-oster
Copy link

We are doing this by editing ConsulServerList.java. The getServers() method calls client.getCatalogService( this.serviceId, QueryParams.DEFAULT);
when it needs to support calling:
client.getCatalogService(this.serviceId, tags, QueryParams.DEFAULT);

This behavior change should be able to be wired in via the conditional ribbonServerList in ConsulRibbonClientConfiguration:

    @Bean
    @ConditionalOnMissingBean
    public ServerList<?> ribbonServerList(IClientConfig config) {
        ConsulServerList serverList = new ConsulServerList(client, properties);
        serverList.initWithNiwsConfig(config);
        return serverList;
    }

We ran into trouble trying to inject that replacement, in that we couldn't seem to load it at a time when IClientConfig is available, but before the conditional check in ConsulRibbonClientConfiguration.

Any pointers?

@spencergibb
Copy link
Member

Usually that means the @Configuration for your server list is getting picked up by component scanning.

@outcomes-scott-oster
Copy link

Is this the pattern we should follow then?
https://github.com/spring-cloud-samples/tests/tree/master/ribbon-default-config/src/main/java/demo

Basically create a @configuration class (that defines the ribbonServerList method) that is not loaded via componentscan or other mechanisms, then reference it in the @RibbonClients annotation? For example:
@RibbonClients(defaultConfiguration=MyDefaultRibbonConfig.class)

I'm trying to get this working with Zuul, so I'd put that annotation on the main zuul application which has @EnableDiscoveryClient on it.

@spencergibb
Copy link
Member

Yes, that is according to the documentation http://projects.spring.io/spring-cloud/spring-cloud.html#_customizing_the_ribbon_client

@outcomes-scott-oster
Copy link

Ok, I will give it a shot. The documentation more seemed to imply it shouldn't be componentscanned unless you wanted it to be globally used (which I am fine with):

The FooConfiguration has to be @configuration but take care that it is not in a @componentscan for the main application context, otherwise it will be shared by all the @RibbonClients.

@spencergibb
Copy link
Member

yes, but you would also have to define you're own IClientConfig since there is no global one.

@spencergibb spencergibb added this to the 1.0.0 milestone Jan 19, 2016
@spencergibb spencergibb self-assigned this Jan 19, 2016
spencergibb pushed a commit that referenced this issue Apr 14, 2017
remove alt attribute in <div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants