Closed JagmohanSharma closed 5 years ago
Can I ask why you want a custom ConsulDiscoveryClient
?
@spencergibb Actually as we are using CommonsInstanceDiscovery in our turbine application which gets instances data from consulDiscoveryClient. we have configured services at consul in a manner that we require certain formatting of tags before we can use them. And also we are making use of KvStore to keep a property called "hystrix_enabled" which is used to fetch only hystrix enabled services from consul. As each service is storing this property in its kv store(kvPrefix).
Now as InstanceObservable keep fetching instances from consulDiscoveryClient so we have to override consulDiscoveryClient before it actually start each instance monitor by making call to ClusterMonitorInstanceManager.
Also we got certain cases where we need to add additional meta data for containing hystrix stream url for any particular service instances which is later used in overridden AggregateClusterMonitor's ClusterConfigBasedUrlClosure directly. So we had to use custom consulDiscoveryClient to accommodate these requirements.
any feedback or help on this?
The issue seems to be in the ConditionalOnClass in ConditionalOnConsulEnabled `public @interface ConditionalOnConsulEnabled {
class OnConsulEnabledCondition extends AllNestedConditions {
...
@ConditionalOnClass(ConsulClient.class)
static class FoundClass {}
}
}`
It specifically requires, com.ecwid.consul.v1.ConsulClient
I also found this trying to replace the client. Our use case is security related: we are using Consul ACLs with everything blacklisted, so no anonymous requests are permitted; however the ConsulClient does not send the token for a variety of request (our issue was with deregister).
spring-cloud-consul has hard dependencies throughout on ConsulClient
. I'm not sure it's worth much without it.
But can we think about default scope for LocalResolver to change as it is currently not possible to provide parameter of type LocalResolver as being done in ConsulDiscoveryClientConfiguration?
I've got a more Consul-related use case here: Process the list of services in org.springframework.cloud.consul.discovery.ConsulDiscoveryClient#getServices()
to perform advanced filtering/transformation of services before handing them off to org.springframework.cloud.netflix.zuul.filters.discovery.DiscoveryClientRouteLocator#locateRoutes()
.
Previously, in Camden.SR6
, I used this way to customize the instance id:
public class DiscoveryConfiguration {
@Autowired
private ConsulDiscoveryClientConfiguration configuration;
@Autowired
private ApplicationContext context;
@Bean
public ConsulLifecycle consulLifecycle(ConsulDiscoveryProperties discoveryProperties,
HeartbeatProperties heartbeatProperties) {
String suffix;
try {
suffix = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
suffix = UUID.randomUUID().toString();
log.error("get hostname error, {}", e.getMessage());
}
String instanceId = context.getId() + ConsulLifecycle.SEPARATOR + suffix;
log.info("register service id: {}", instanceId);
discoveryProperties.setInstanceId(instanceId);
return configuration.consulLifecycle(discoveryProperties, heartbeatProperties);
}
}
But after I upgrade to Dalston.SR3
, ConsulLifecycle
has been deprecated and consulLifecycle
method has been removed. :(
How can I customize the instance id now? I know we can give a pattern in the bootstrap.yml
, but I lost the chance to get hostname.
spring-consul how to Subscribe to healthy services??
@zhuSilence please ask unrelated questions on stack overflow or gitter
I don't think this is an issue anymore, can anyone confirm?
Not a problem with me now. Go ahead!
@spencergibb I need to override ConsulDiscoveryClient, so for that I am making configuration by defining this bean,
But this is not able to find ConsulLifecycle bean when I upgraded to 1.2.0.RELEASE version as it is giving error with
Even if I tried to get ConsulLifecycle bean from applicationContext , still it comes as null only.
Now if I want to provide parameter of type LocalResolver as being done in ConsulDiscoveryClientConfiguration
But this can not be done in our configuration class as you have set default scope for LocalResolver in ConsulDiscoveryClient
Can you guide us to resolve this issue as why we are not getting ConsulLifecycle bean in application context and also would it be required to changes the scope of LocalResolver to public so that this can be used while overriding ConsulDiscoveryClient.
Any help would be appreciated.