1

when I look at the implementation of RibbonConfig in demos around the web, I notice they always use the IClientConfig config parameter, but they never actually use it. For example:

@Autowired
IClientConfig ribbonClientConfig;


@Bean
public IRule ribbonRule(IClientConfig config) { // This parameter is never used
    return new AvailabilityFilteringRule();
}

@Bean
public IPing ribbonPing(IClientConfig config) {
    return new DummyPing();
}

Do you guys know what the IClientConfig config parameter used for? It wasn't used within the method itself in this case.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Kuge4399
  • 69
  • 1
  • 8

1 Answers1

2

I found a very similar example in Moises Macero's book: Learn Microservices with Spring Boot, A Practical Approach to RESTful... e.g:

public class RibbonConfiguration {

@Bean
public IPing ribbonPing(IClientConfig config) {
    return new PingUrl(false, "/health");
}

@Bean
public IRule ribbonRule(IClientConfig config) {
    return new AvailabilityFilteringRule();
}}

The scope of this configuration is changing the default Ribbon load balancing strategy.While Moreover in the official documentation I found this:

@Configuration
class DefaultRibbonConfig {
   @Bean
   public IRule ribbonRule() {
      return new BestAvailableRule();
   }

  @Bean
  public IPing ribbonPing() {
    return new PingUrl();
}

  @Bean
   public ServerList<Server> ribbonServerList(IClientConfig config) {
    return new RibbonClientDefaultConfigurationTestsConfig.BazServiceList(config);
}

 @Bean
 public ServerListSubsetFilter serverListFilter() {
     ServerListSubsetFilter filter = new ServerListSubsetFilter();
     return filter;
  }

}

As you can see, the first two methods are without IClientConfig parameter, here official docs: Customizing the Default for All Ribbon Clients

So I came back to my config file and I removed IClientConfig parmeter and the program still works. In my opinion IClientConfig is useless in this moment. But you can refer to IClientConfig author's comment: IClientConfig

Defines the client configuration used by various APIs to initialize clients or load balancers and for method execution.