mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
仍有两个测试过不了
1. NacosConfigurationXmlJsonTest#contextLoads 2. NacosConfigurationNoSuffixTest#contextLoads Merge branch 'master' into finchley
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
@@ -91,7 +91,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>3.4.12</version>
|
||||
<version>3.4.14</version>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
@@ -37,11 +37,16 @@ import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_RETRIES;
|
||||
* Spring Cloud Service-to-Service call is transported by Dubbo under the hood, there are
|
||||
* two main scenarios:
|
||||
* <ol>
|
||||
* <li>{@link FeignClient @FeignClient} annotated classes: If
|
||||
* {@link DubboTransported @DubboTransported} annotated classes, the invocation of all
|
||||
* methods of {@link FeignClient @FeignClient} annotated classes. If
|
||||
* {@link DubboTransported @DubboTransported} annotated methods of
|
||||
* {@link FeignClient @FeignClient} annotated classes.</li>
|
||||
* <li>{@link FeignClient @FeignClient} annotated classes:
|
||||
* <ul>
|
||||
* If {@link DubboTransported @DubboTransported} annotated classes, the invocation of all
|
||||
* methods of {@link FeignClient @FeignClient} annotated classes.
|
||||
* </ul>
|
||||
* <ul>
|
||||
* If {@link DubboTransported @DubboTransported} annotated methods of
|
||||
* {@link FeignClient @FeignClient} annotated classes.
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li>{@link LoadBalanced @LoadBalanced} {@link RestTemplate} annotated field, method and
|
||||
* parameters</li>
|
||||
* </ol>
|
||||
|
@@ -111,8 +111,7 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
loadBalancerInterceptorBean = retryLoadBalancerInterceptor != null
|
||||
? retryLoadBalancerInterceptor
|
||||
: loadBalancerInterceptor;
|
||||
? retryLoadBalancerInterceptor : loadBalancerInterceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +145,7 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
||||
* Gets the annotation attributes {@link RestTemplate} bean being annotated
|
||||
* {@link DubboTransported @DubboTransported}.
|
||||
* @param beanName the bean name of {@link LoadBalanced @LoadBalanced}
|
||||
* {@link RestTemplate}
|
||||
* {@link RestTemplate}
|
||||
* @param attributesResolver {@link DubboTransportedAttributesResolver}
|
||||
* @return non-null {@link Map}
|
||||
*/
|
||||
@@ -171,8 +170,8 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements
|
||||
* {@link LoadBalancerInterceptor} Bean.
|
||||
* @param restTemplate {@link LoadBalanced @LoadBalanced} {@link RestTemplate} Bean
|
||||
* @param dubboTranslatedAttributes the annotation dubboTranslatedAttributes
|
||||
* {@link RestTemplate} bean being annotated
|
||||
* {@link DubboTransported @DubboTransported}
|
||||
* {@link RestTemplate} bean being annotated
|
||||
* {@link DubboTransported @DubboTransported}
|
||||
*/
|
||||
private void adaptRestTemplate(RestTemplate restTemplate,
|
||||
Map<String, Object> dubboTranslatedAttributes) {
|
||||
|
@@ -35,8 +35,8 @@ import static com.alibaba.cloud.dubbo.autoconfigure.DubboOpenFeignAutoConfigurat
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@ConditionalOnClass(name = { "feign.Feign", TARGETER_CLASS_NAME })
|
||||
@AutoConfigureAfter(name = {
|
||||
"org.springframework.cloud.openfeign.FeignAutoConfiguration" })
|
||||
@AutoConfigureAfter(
|
||||
name = { "org.springframework.cloud.openfeign.FeignAutoConfiguration" })
|
||||
@Configuration
|
||||
public class DubboOpenFeignAutoConfiguration {
|
||||
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.alibaba.cloud.dubbo.autoconfigure;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -98,11 +99,12 @@ import static org.springframework.util.StringUtils.hasText;
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.springframework.cloud.client.discovery.DiscoveryClient")
|
||||
@ConditionalOnProperty(name = "spring.cloud.discovery.enabled", matchIfMissing = true)
|
||||
@AutoConfigureAfter(name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME }, value = {
|
||||
DubboServiceRegistrationAutoConfiguration.class })
|
||||
@AutoConfigureAfter(
|
||||
name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
ZOOKEEPER_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
CONSUL_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
NACOS_DISCOVERY_AUTO_CONFIGURATION_CLASS_NAME },
|
||||
value = { DubboServiceRegistrationAutoConfiguration.class })
|
||||
public class DubboServiceDiscoveryAutoConfiguration {
|
||||
|
||||
/**
|
||||
@@ -202,7 +204,7 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
||||
* {@link #defaultHeartbeatEventChangePredicate()} method providers the default
|
||||
* implementation to detect whether the {@link HeartbeatEvent#getValue() state} is
|
||||
* changed or not. If and only if changed, the
|
||||
* {@link #dispatchServiceInstancesChangedEvent(String, List)} will be executed.
|
||||
* {@link #dispatchServiceInstancesChangedEvent(String, Collection)} will be executed.
|
||||
* <p>
|
||||
* <b>Note : </b> Spring Cloud {@link HeartbeatEvent} has a critical flaw that can't
|
||||
* figure out which service was changed precisely, it's just used for a notification
|
||||
@@ -361,7 +363,7 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
||||
|
||||
/**
|
||||
* Zookeeper uses {@link TreeCacheEvent} to trigger
|
||||
* {@link #dispatchServiceInstancesChangedEvent(String, List)} , thus
|
||||
* {@link #dispatchServiceInstancesChangedEvent(String, Collection)} , thus
|
||||
* {@link HeartbeatEvent} handle is always ignored.
|
||||
* @return <code>false</code> forever
|
||||
*/
|
||||
@@ -429,7 +431,7 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to {@link #dispatchServiceInstancesChangedEvent(String, List)
|
||||
* Try to {@link #dispatchServiceInstancesChangedEvent(String, Collection)
|
||||
* dispatch} {@link ServiceInstancesChangedEvent} before
|
||||
* {@link ZookeeperServiceWatch#childEvent(CuratorFramework, TreeCacheEvent)}
|
||||
* execution if required.
|
||||
@@ -527,7 +529,7 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
||||
|
||||
/**
|
||||
* Nacos uses {@link EventListener} to trigger.
|
||||
* {@link #dispatchServiceInstancesChangedEvent(String, List)} , thus
|
||||
* {@link #dispatchServiceInstancesChangedEvent(String, Collection)} , thus
|
||||
* {@link HeartbeatEvent} handle is always ignored
|
||||
* @return <code>false</code> forever
|
||||
*/
|
||||
|
@@ -16,22 +16,31 @@
|
||||
|
||||
package com.alibaba.cloud.dubbo.autoconfigure;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME;
|
||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
|
||||
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.ADDRESS;
|
||||
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL;
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
|
||||
import com.alibaba.cloud.dubbo.autoconfigure.condition.MissingSpringCloudRegistryConfigPropertyCondition;
|
||||
import com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapStartCommandLineRunner;
|
||||
import com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapWrapper;
|
||||
import com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent;
|
||||
import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository;
|
||||
import com.alibaba.cloud.dubbo.registry.DubboServiceRegistrationEventPublishingAspect;
|
||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreDeregisteredEvent;
|
||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent;
|
||||
import com.ecwid.consul.v1.agent.model.NewService;
|
||||
import com.netflix.appinfo.InstanceInfo;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
||||
import org.apache.dubbo.config.spring.ServiceBean;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
@@ -42,7 +51,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
||||
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
|
||||
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
|
||||
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration;
|
||||
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration;
|
||||
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry;
|
||||
@@ -53,19 +64,15 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME;
|
||||
import static com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
|
||||
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.ADDRESS;
|
||||
import static com.alibaba.cloud.dubbo.registry.SpringCloudRegistryFactory.PROTOCOL;
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
|
||||
/**
|
||||
* Dubbo Service Registration Auto-{@link Configuration}.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
@Configuration
|
||||
@Import({ DubboServiceRegistrationEventPublishingAspect.class })
|
||||
@Import({ DubboServiceRegistrationEventPublishingAspect.class,
|
||||
DubboBootstrapStartCommandLineRunner.class })
|
||||
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
|
||||
@AutoConfigureAfter(name = { EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
CONSUL_AUTO_SERVICE_AUTO_CONFIGURATION_CLASS_NAME,
|
||||
@@ -105,10 +112,41 @@ public class DubboServiceRegistrationAutoConfiguration {
|
||||
return new RegistryConfig(ADDRESS, PROTOCOL);
|
||||
}
|
||||
|
||||
private Map<ServiceRegistry<Registration>, Set<Registration>> registrations = new ConcurrentHashMap<>();
|
||||
|
||||
@EventListener(DubboBootstrapStartedEvent.class)
|
||||
public void onDubboBootstrapStarted(DubboBootstrapStartedEvent event) {
|
||||
if (!event.getSource().isReady()) {
|
||||
return;
|
||||
}
|
||||
registrations.forEach(
|
||||
(registry, registrations) -> registrations.forEach(registration -> {
|
||||
attachDubboMetadataServiceMetadata(registration);
|
||||
registry.register(registration);
|
||||
}));
|
||||
}
|
||||
|
||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||
public void onServiceInstancePreRegistered(ServiceInstancePreRegisteredEvent event) {
|
||||
Registration registration = event.getSource();
|
||||
attachDubboMetadataServiceMetadata(registration);
|
||||
if (!DubboBootstrap.getInstance().isStarted()) {
|
||||
ServiceRegistry<Registration> registry = event.getRegistry();
|
||||
synchronized (registry) {
|
||||
registrations.putIfAbsent(registry, new HashSet<>());
|
||||
registrations.get(registry).add(registration);
|
||||
}
|
||||
}
|
||||
else {
|
||||
attachDubboMetadataServiceMetadata(registration);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EventListener(ServiceInstancePreDeregisteredEvent.class)
|
||||
public void onServiceInstancePreDeregistered(
|
||||
ServiceInstancePreDeregisteredEvent event) {
|
||||
ServiceRegistry<Registration> registry = event.getRegistry();
|
||||
registrations.remove(registry);
|
||||
}
|
||||
|
||||
private void attachDubboMetadataServiceMetadata(Registration registration) {
|
||||
@@ -131,21 +169,66 @@ public class DubboServiceRegistrationAutoConfiguration {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(name = EUREKA_CLIENT_AUTO_CONFIGURATION_CLASS_NAME)
|
||||
@Aspect
|
||||
class EurekaConfiguration implements SmartInitializingSingleton {
|
||||
|
||||
@Autowired
|
||||
private ObjectProvider<Collection<ServiceBean>> serviceBeans;
|
||||
|
||||
@EventListener(DubboBootstrapStartedEvent.class)
|
||||
public void onDubboBootstrapStarted(DubboBootstrapStartedEvent event) {
|
||||
DubboBootstrapWrapper wrapper = event.getSource();
|
||||
if (!wrapper.isReady()) {
|
||||
return;
|
||||
}
|
||||
registrations.forEach(
|
||||
(registry, registrations) -> registrations.removeIf(registration -> {
|
||||
if (!(registration instanceof EurekaRegistration)) {
|
||||
return false;
|
||||
}
|
||||
EurekaRegistration eurekaRegistration = (EurekaRegistration) registration;
|
||||
InstanceInfo instanceInfo = eurekaRegistration
|
||||
.getApplicationInfoManager().getInfo();
|
||||
|
||||
EurekaInstanceConfigBean config = (EurekaInstanceConfigBean) eurekaRegistration
|
||||
.getInstanceConfig();
|
||||
config.setInitialStatus(InstanceInfo.InstanceStatus.UP);
|
||||
|
||||
attachDubboMetadataServiceMetadata(instanceInfo.getMetadata());
|
||||
eurekaRegistration.getApplicationInfoManager()
|
||||
.registerAppMetadata(instanceInfo.getMetadata());
|
||||
eurekaRegistration.getApplicationInfoManager()
|
||||
.setInstanceStatus(InstanceInfo.InstanceStatus.UP);
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||
public void onServiceInstancePreRegistered(
|
||||
ServiceInstancePreRegisteredEvent event) {
|
||||
Registration registration = event.getSource();
|
||||
EurekaRegistration eurekaRegistration = EurekaRegistration.class
|
||||
.cast(registration);
|
||||
InstanceInfo instanceInfo = eurekaRegistration.getApplicationInfoManager()
|
||||
.getInfo();
|
||||
attachDubboMetadataServiceMetadata(instanceInfo.getMetadata());
|
||||
if (!(registration instanceof EurekaRegistration)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DubboBootstrap.getInstance().isStarted()) {
|
||||
EurekaRegistration eurekaRegistration = (EurekaRegistration) registration;
|
||||
InstanceInfo instanceInfo = eurekaRegistration.getApplicationInfoManager()
|
||||
.getInfo();
|
||||
|
||||
EurekaInstanceConfigBean config = (EurekaInstanceConfigBean) eurekaRegistration
|
||||
.getInstanceConfig();
|
||||
config.setInitialStatus(InstanceInfo.InstanceStatus.UP);
|
||||
|
||||
attachDubboMetadataServiceMetadata(instanceInfo.getMetadata());
|
||||
eurekaRegistration.getApplicationInfoManager()
|
||||
.registerAppMetadata(instanceInfo.getMetadata());
|
||||
}
|
||||
else {
|
||||
EurekaRegistration eurekaRegistration = (EurekaRegistration) registration;
|
||||
EurekaInstanceConfigBean config = (EurekaInstanceConfigBean) eurekaRegistration
|
||||
.getInstanceConfig();
|
||||
config.setInitialStatus(InstanceInfo.InstanceStatus.STARTING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,21 +253,28 @@ public class DubboServiceRegistrationAutoConfiguration {
|
||||
@AutoConfigureOrder
|
||||
class ConsulConfiguration {
|
||||
|
||||
/**
|
||||
* Handle the pre-registered event of {@link ServiceInstance} for Consul.
|
||||
* @param event {@link ServiceInstancePreRegisteredEvent}
|
||||
*/
|
||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||
public void onServiceInstancePreRegistered(
|
||||
ServiceInstancePreRegisteredEvent event) {
|
||||
Registration registration = event.getSource();
|
||||
Class<?> registrationClass = AopUtils.getTargetClass(registration);
|
||||
String registrationClassName = registrationClass.getName();
|
||||
if (CONSUL_AUTO_SERVICE_AUTO_REGISTRATION_CLASS_NAME
|
||||
.equalsIgnoreCase(registrationClassName)) {
|
||||
ConsulRegistration consulRegistration = (ConsulRegistration) registration;
|
||||
attachURLsIntoMetadata(consulRegistration);
|
||||
@EventListener(DubboBootstrapStartedEvent.class)
|
||||
public void attachURLsIntoMetadataBeforeReRegist(
|
||||
DubboBootstrapStartedEvent event) {
|
||||
if (!event.getSource().isReady()) {
|
||||
return;
|
||||
}
|
||||
registrations.entrySet().removeIf(entry -> {
|
||||
Set<Registration> registrations = entry.getValue();
|
||||
registrations.removeIf(registration -> {
|
||||
Class<?> registrationClass = AopUtils.getTargetClass(registration);
|
||||
String registrationClassName = registrationClass.getName();
|
||||
return !CONSUL_AUTO_SERVICE_AUTO_REGISTRATION_CLASS_NAME
|
||||
.equalsIgnoreCase(registrationClassName);
|
||||
});
|
||||
return registrations.isEmpty();
|
||||
});
|
||||
|
||||
registrations.forEach(
|
||||
(registry, registrations) -> registrations.forEach(registration -> {
|
||||
ConsulRegistration consulRegistration = (ConsulRegistration) registration;
|
||||
attachURLsIntoMetadata(consulRegistration);
|
||||
}));
|
||||
}
|
||||
|
||||
private void attachURLsIntoMetadata(ConsulRegistration consulRegistration) {
|
||||
|
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* publish Dubbo microsystem startup finish event.
|
||||
*
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class DubboBootstrapStartCommandLineRunner
|
||||
implements CommandLineRunner, ApplicationEventPublisherAware {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(
|
||||
ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
applicationEventPublisher.publishEvent(
|
||||
new DubboBootstrapStartedEvent(DubboBootstrapWrapper.getInstance()));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
||||
|
||||
/**
|
||||
* Wrapper DubboBootstrap operation.
|
||||
*
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
public final class DubboBootstrapWrapper {
|
||||
|
||||
private DubboBootstrapWrapper() {
|
||||
}
|
||||
|
||||
private static final DubboBootstrapWrapper INSTANCE = new DubboBootstrapWrapper();
|
||||
|
||||
public static DubboBootstrapWrapper getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
return DubboBootstrap.getInstance().isStarted()
|
||||
&& DubboBootstrap.getInstance().isInitialized();
|
||||
}
|
||||
|
||||
public DubboBootstrap getDubboBootstrap() {
|
||||
return DubboBootstrap.getInstance();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap.event;
|
||||
|
||||
import com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapWrapper;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* Dubbo microsytem start finish event, every thing is ready.
|
||||
*
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
public class DubboBootstrapStartedEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
* Create a new {@code DubboBootstrapStartedEvent}.
|
||||
* @param source the object on which the event initially occurred or with which the
|
||||
* event is associated (never {@code null})
|
||||
*/
|
||||
public DubboBootstrapStartedEvent(DubboBootstrapWrapper source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DubboBootstrapWrapper getSource() {
|
||||
return (DubboBootstrapWrapper) super.getSource();
|
||||
}
|
||||
|
||||
}
|
@@ -141,8 +141,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor
|
||||
DEFAULT_PROTOCOL);
|
||||
|
||||
return isRestProtocol(protocol)
|
||||
? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME)
|
||||
: null;
|
||||
? environment.getProperty(PROTOCOL_PORT_PROPERTY_NAME) : null;
|
||||
}
|
||||
|
||||
private String getRestPortFromProtocolsProperties(
|
||||
|
@@ -41,7 +41,7 @@ public class HttpRequestConsumersMatcher extends AbstractHttpRequestMatcher {
|
||||
/**
|
||||
* Creates a new instance from 0 or more "consumes" expressions.
|
||||
* @param consumes consumes expressions if 0 expressions are provided, the condition
|
||||
* will match to every request
|
||||
* will match to every request
|
||||
*/
|
||||
public HttpRequestConsumersMatcher(String... consumes) {
|
||||
this(consumes, null);
|
||||
|
@@ -34,10 +34,10 @@ public class HttpRequestParamsMatcher extends AbstractHttpRequestMatcher {
|
||||
|
||||
/**
|
||||
* @param params The pattern of params :
|
||||
* <ul>
|
||||
* <li>name=value</li>
|
||||
* <li>name</li>
|
||||
* </ul>
|
||||
* <ul>
|
||||
* <li>name=value</li>
|
||||
* <li>name</li>
|
||||
* </ul>
|
||||
*/
|
||||
public HttpRequestParamsMatcher(String... params) {
|
||||
this.expressions = parseExpressions(params);
|
||||
|
@@ -83,7 +83,7 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
||||
/**
|
||||
* Caches the IDs of {@link ApplicationListener}.
|
||||
*/
|
||||
private static final Set<String> registerListeners = new HashSet<>();
|
||||
private static final Set<String> REGISTER_LISTENERS = new HashSet<>();
|
||||
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@@ -215,7 +215,7 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
||||
private void registerServiceInstancesChangedListener(URL url,
|
||||
ApplicationListener<ServiceInstancesChangedEvent> listener) {
|
||||
String listenerId = generateId(url);
|
||||
if (registerListeners.add(listenerId)) {
|
||||
if (REGISTER_LISTENERS.add(listenerId)) {
|
||||
applicationContext.addApplicationListener(listener);
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
||||
.map(templateURL -> templateURL.removeParameter(PID_KEY))
|
||||
.map(templateURL -> {
|
||||
String protocol = templateURL.getProtocol();
|
||||
int port = repository.getDubboProtocolPort(serviceInstance,
|
||||
Integer port = repository.getDubboProtocolPort(serviceInstance,
|
||||
protocol);
|
||||
if (Objects.equals(templateURL.getHost(), host)
|
||||
&& Objects.equals(templateURL.getPort(), port)) { // use
|
||||
@@ -300,15 +300,27 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
||||
return templateURL;
|
||||
}
|
||||
|
||||
URLBuilder clonedURLBuilder = from(templateURL) // remove the
|
||||
// parameters from
|
||||
// the template
|
||||
// URL
|
||||
.setHost(host) // reset the host
|
||||
.setPort(port); // reset the port
|
||||
if (port == null) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(
|
||||
"The protocol[{}] port of Dubbo service instance[host : {}] "
|
||||
+ "can't be resolved",
|
||||
protocol, host);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
URLBuilder clonedURLBuilder = from(templateURL) // remove the
|
||||
// parameters from
|
||||
// the template
|
||||
// URL
|
||||
.setHost(host) // reset the host
|
||||
.setPort(port); // reset the port
|
||||
|
||||
return clonedURLBuilder.build();
|
||||
}).forEach(clonedExportedURLs::add);
|
||||
return clonedURLBuilder.build();
|
||||
}
|
||||
|
||||
}).filter(Objects::nonNull).forEach(clonedExportedURLs::add);
|
||||
});
|
||||
return clonedExportedURLs;
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.alibaba.cloud.dubbo.registry;
|
||||
|
||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreDeregisteredEvent;
|
||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancePreRegisteredEvent;
|
||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstanceRegisteredEvent;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.context.ApplicationEventPublisherAware;
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see ServiceInstancePreRegisteredEvent
|
||||
* @see ServiceInstanceRegisteredEvent
|
||||
* @see ServiceInstancePreDeregisteredEvent
|
||||
*/
|
||||
@Aspect
|
||||
public class DubboServiceRegistrationEventPublishingAspect
|
||||
@@ -41,18 +43,29 @@ public class DubboServiceRegistrationEventPublishingAspect
|
||||
/**
|
||||
* The pointcut expression for {@link ServiceRegistry#register(Registration)}.
|
||||
*/
|
||||
public static final String REGISTER_POINTCUT_EXPRESSION = "execution(* org.springframework.cloud.client.serviceregistry.ServiceRegistry.register(*)) && args(registration)";
|
||||
public static final String REGISTER_POINTCUT_EXPRESSION = "execution(* org.springframework.cloud.client.serviceregistry.ServiceRegistry.register(*)) && target(registry) && args(registration)";
|
||||
|
||||
/**
|
||||
* The pointcut expression for {@link ServiceRegistry#deregister(Registration)}.
|
||||
*/
|
||||
public static final String DEREGISTER_POINTCUT_EXPRESSION = "execution(* org.springframework.cloud.client.serviceregistry.ServiceRegistry.deregister(*)) && target(registry) && args(registration)";
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Before(REGISTER_POINTCUT_EXPRESSION)
|
||||
public void beforeRegister(Registration registration) {
|
||||
applicationEventPublisher
|
||||
.publishEvent(new ServiceInstancePreRegisteredEvent(registration));
|
||||
@Before(value = REGISTER_POINTCUT_EXPRESSION, argNames = "registry, registration")
|
||||
public void beforeRegister(ServiceRegistry registry, Registration registration) {
|
||||
applicationEventPublisher.publishEvent(
|
||||
new ServiceInstancePreRegisteredEvent(registry, registration));
|
||||
}
|
||||
|
||||
@After(REGISTER_POINTCUT_EXPRESSION)
|
||||
public void afterRegister(Registration registration) {
|
||||
@Before(value = DEREGISTER_POINTCUT_EXPRESSION, argNames = "registry, registration")
|
||||
public void beforeDeregister(ServiceRegistry registry, Registration registration) {
|
||||
applicationEventPublisher.publishEvent(
|
||||
new ServiceInstancePreDeregisteredEvent(registry, registration));
|
||||
}
|
||||
|
||||
@After(value = REGISTER_POINTCUT_EXPRESSION, argNames = "registry, registration")
|
||||
public void afterRegister(ServiceRegistry registry, Registration registration) {
|
||||
applicationEventPublisher
|
||||
.publishEvent(new ServiceInstanceRegisteredEvent(registration));
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.registry.event;
|
||||
|
||||
import org.springframework.cloud.client.serviceregistry.Registration;
|
||||
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* The
|
||||
* before-{@link org.springframework.cloud.client.serviceregistry.ServiceRegistry#register(org.springframework.cloud.client.serviceregistry.Registration)
|
||||
* register} event for {@link org.springframework.cloud.client.ServiceInstance}.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public class ServiceInstancePreDeregisteredEvent extends ApplicationEvent {
|
||||
|
||||
private final ServiceRegistry<Registration> registry;
|
||||
|
||||
public ServiceInstancePreDeregisteredEvent(ServiceRegistry<Registration> registry,
|
||||
Registration source) {
|
||||
super(source);
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registration getSource() {
|
||||
return (Registration) super.getSource();
|
||||
}
|
||||
|
||||
public ServiceRegistry<Registration> getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
}
|
@@ -29,8 +29,12 @@ import org.springframework.context.ApplicationEvent;
|
||||
*/
|
||||
public class ServiceInstancePreRegisteredEvent extends ApplicationEvent {
|
||||
|
||||
public ServiceInstancePreRegisteredEvent(Registration source) {
|
||||
private final ServiceRegistry<Registration> registry;
|
||||
|
||||
public ServiceInstancePreRegisteredEvent(ServiceRegistry<Registration> registry,
|
||||
Registration source) {
|
||||
super(source);
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,4 +42,8 @@ public class ServiceInstancePreRegisteredEvent extends ApplicationEvent {
|
||||
return (Registration) super.getSource();
|
||||
}
|
||||
|
||||
public ServiceRegistry<Registration> getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -127,11 +127,12 @@ public class DubboGenericServiceFactory {
|
||||
new PropertyEditorSupport() {
|
||||
|
||||
@Override
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
public void setAsText(String text)
|
||||
throws java.lang.IllegalArgumentException {
|
||||
// Trim all whitespace
|
||||
String content = StringUtils.trimAllWhitespace(text);
|
||||
if (!StringUtils.hasText(content)) { // No content , ignore
|
||||
// directly
|
||||
// directly
|
||||
return;
|
||||
}
|
||||
// replace "=" to ","
|
||||
|
Reference in New Issue
Block a user