@Configuration(proxyBeanMethods=false)
@ConditionalOnClass(name="org.springframework.cloud.client.discovery.DiscoveryClient")
@ConditionalOnProperty(name="spring.cloud.discovery.enabled",
matchIfMissing=true)
@AutoConfigureAfter(name={"org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration","org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryAutoConfiguration","org.springframework.cloud.consul.discovery.ConsulDiscoveryClientConfiguration","com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration"},
value=DubboServiceRegistrationAutoConfiguration.class)
public class DubboServiceDiscoveryAutoConfiguration
extends Object
Configuration (after
DubboServiceRegistrationAutoConfiguration).DubboServiceRegistrationAutoConfiguration,
Configuration,
DiscoveryClient| Modifier and Type | Class and Description |
|---|---|
class |
DubboServiceDiscoveryAutoConfiguration.EurekaConfiguration
Eureka Customized Configuration.
|
class |
DubboServiceDiscoveryAutoConfiguration.ZookeeperConfiguration
Zookeeper Customized Configuration.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME
ConsulDiscoveryClientConfiguration.
|
static String |
NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME
NacosDiscoveryAutoConfiguration.
|
static String |
ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME
ZookeeperDiscoveryAutoConfiguration.
|
| Constructor and Description |
|---|
DubboServiceDiscoveryAutoConfiguration(DubboServiceMetadataRepository dubboServiceMetadataRepository,
org.springframework.context.ApplicationEventPublisher applicationEventPublisher,
org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient,
org.springframework.beans.factory.ObjectProvider<Predicate<org.springframework.cloud.client.discovery.event.HeartbeatEvent>> heartbeatEventChangedPredicate) |
| Modifier and Type | Method and Description |
|---|---|
Predicate<org.springframework.cloud.client.discovery.event.HeartbeatEvent> |
defaultHeartbeatEventChangePredicate()
The default
Predicate implementation of HeartbeatEvent based on the
comparison between previous and current state
value, the DiscoveryClient implementation may override current. |
void |
onHeartbeatEvent(org.springframework.cloud.client.discovery.event.HeartbeatEvent event)
Dispatch a
ServiceInstancesChangedEvent when the HeartbeatEvent
raised, use for these scenarios:
Eureka : CloudEurekaClient.onCacheRefreshed() publishes a
HeartbeatEvent instead of CacheRefreshedEvent
Zookeeper :
ZookeeperServiceWatch.childEvent(CuratorFramework, TreeCacheEvent)
publishes a HeartbeatEvent when
the services' root path has been
changed
Consul : ConsulCatalogWatch.catalogServicesWatch() publishes a
HeartbeatEvent when
Consul's Blocking
Queries response
Nacos : NacosWatch.nacosServicesWatch() publishes a
HeartbeatEvent under a TaskScheduler every
NacosDiscoveryProperties.getWatchDelay() milliseconds
|
public static final String ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME
public static final String CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME
public static final String NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME
public DubboServiceDiscoveryAutoConfiguration(DubboServiceMetadataRepository dubboServiceMetadataRepository, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, org.springframework.cloud.client.discovery.DiscoveryClient discoveryClient, org.springframework.beans.factory.ObjectProvider<Predicate<org.springframework.cloud.client.discovery.event.HeartbeatEvent>> heartbeatEventChangedPredicate)
@EventListener(value=org.springframework.cloud.client.discovery.event.HeartbeatEvent.class) public void onHeartbeatEvent(org.springframework.cloud.client.discovery.event.HeartbeatEvent event)
ServiceInstancesChangedEvent when the HeartbeatEvent
raised, use for these scenarios:
CloudEurekaClient.onCacheRefreshed() publishes a
HeartbeatEvent instead of CacheRefreshedEventZookeeperServiceWatch.childEvent(CuratorFramework, TreeCacheEvent)
publishes a HeartbeatEvent when
the services' root path has been
changedConsulCatalogWatch.catalogServicesWatch() publishes a
HeartbeatEvent when
Consul's Blocking
Queries responseNacosWatch.nacosServicesWatch() publishes a
HeartbeatEvent under a TaskScheduler every
NacosDiscoveryProperties.getWatchDelay() milliseconds
In order to reduce the duplicated handling for
ServiceInstancesChangedEvent,
defaultHeartbeatEventChangePredicate() method providers the default
implementation to detect whether the state is
changed or not. If and only if changed, the
#dispatchServiceInstancesChangedEvent(String, Collection) will be executed.
Note : Spring Cloud HeartbeatEvent has a critical flaw that can't
figure out which service was changed precisely, it's just used for a notification
that the subscribed
services used to notify the Dubbo consumer
cached URLs. Because of some DiscoveryClient implementations
have the better and fine-grained the event mechanism for service instances change,
thus HeartbeatEvent handle will be ignored in these scenarios:
Watcher, see
DubboServiceDiscoveryAutoConfiguration.ZookeeperConfiguration.heartbeatEventChangedPredicate()EventListener , see
NacosConfiguration#heartbeatEventChangedPredicate()
If the customized DiscoveryClient also providers the similar mechanism, the
implementation could declare a Spring Bean of Predicate of
HeartbeatEvent to override default one.
event - the instance of HeartbeatEventHeartbeatEvent@Bean @ConditionalOnMissingBean public Predicate<org.springframework.cloud.client.discovery.event.HeartbeatEvent> defaultHeartbeatEventChangePredicate()
Predicate implementation of HeartbeatEvent based on the
comparison between previous and current state
value, the DiscoveryClient implementation may override current.Predicate HeartbeatEventDubboServiceDiscoveryAutoConfiguration.EurekaConfiguration.heartbeatEventChangedPredicate()Copyright © 2021 Pivotal Software, Inc.. All rights reserved.