1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

sync dubbo in finchley

This commit is contained in:
fangjian0423 2019-04-17 14:37:29 +08:00
parent ade58496fc
commit c98fa4e1f7
14 changed files with 188 additions and 72 deletions

View File

@ -15,7 +15,6 @@
<properties> <properties>
<dubbo.version>2.7.1</dubbo.version> <dubbo.version>2.7.1</dubbo.version>
<dubbo-spring-boot.version>2.7.0</dubbo-spring-boot.version>
<spring-cloud-zookeeper.version>2.0.1.RELEASE</spring-cloud-zookeeper.version> <spring-cloud-zookeeper.version>2.0.1.RELEASE</spring-cloud-zookeeper.version>
<spring-cloud-consul.version>2.0.2.RELEASE</spring-cloud-consul.version> <spring-cloud-consul.version>2.0.2.RELEASE</spring-cloud-consul.version>
<curator.version>4.0.1</curator.version> <curator.version>4.0.1</curator.version>
@ -182,6 +181,13 @@
<version>${dubbo.version}</version> <version>${dubbo.version}</version>
</dependency> </dependency>
<!-- Dubbo Spring Boot Actuator -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-actuator</artifactId>
<version>${dubbo.version}</version>
</dependency>
<!-- Netty --> <!-- Netty -->
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>

View File

@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 org.springframework.cloud.alibaba.dubbo.actuate;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.alibaba.dubbo.actuate.endpoint.DubboRestMetadataEndpoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
/**
* Dubbo Metadata Endpoints Auto-{@link Configuration}
*/
@ConditionalOnClass(name = "org.springframework.boot.actuate.endpoint.annotation.Endpoint")
@PropertySource(value = "classpath:/META-INF/dubbo/default/actuator-endpoints.properties")
@ManagementContextConfiguration
public class DubboMetadataEndpointAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
public DubboRestMetadataEndpoint dubboRestMetadataEndpoint() {
return new DubboRestMetadataEndpoint();
}
}

View File

@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 org.springframework.cloud.alibaba.dubbo.actuate.endpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataService;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
/**
* Dubbo Rest Metadata {@link Endpoint}
*/
@Endpoint(id = "dubborestmetadata")
public class DubboRestMetadataEndpoint {
@Autowired
private DubboMetadataService dubboMetadataService;
@ReadOperation(produces = APPLICATION_JSON_UTF8_VALUE)
public String get() {
return dubboMetadataService.getServiceRestMetadata();
}
}

View File

@ -35,6 +35,7 @@ import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactor
import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor; import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer; import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
import org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
@ -56,7 +57,7 @@ import java.util.Map;
@Configuration @Configuration
@ConditionalOnClass(name = {"org.springframework.web.client.RestTemplate"}) @ConditionalOnClass(name = {"org.springframework.web.client.RestTemplate"})
@AutoConfigureAfter(name = {"org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration"}) @AutoConfigureAfter(name = {"org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration"})
public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClassLoaderAware { public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClassLoaderAware, SmartInitializingSingleton {
private static final Class<DubboTransported> DUBBO_TRANSPORTED_CLASS = DubboTransported.class; private static final Class<DubboTransported> DUBBO_TRANSPORTED_CLASS = DubboTransported.class;
@ -65,9 +66,12 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
@Autowired @Autowired
private DubboServiceMetadataRepository repository; private DubboServiceMetadataRepository repository;
@Autowired @Autowired(required = false)
private LoadBalancerInterceptor loadBalancerInterceptor; private LoadBalancerInterceptor loadBalancerInterceptor;
@Autowired(required = false)
private RetryLoadBalancerInterceptor retryLoadBalancerInterceptor;
@Autowired @Autowired
private ConfigurableListableBeanFactory beanFactory; private ConfigurableListableBeanFactory beanFactory;
@ -86,6 +90,17 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
private ClassLoader classLoader; private ClassLoader classLoader;
/**
* The {@link ClientHttpRequestInterceptor} bean that may be {@link LoadBalancerInterceptor} or {@link RetryLoadBalancerInterceptor}
*/
private ClientHttpRequestInterceptor loadBalancerInterceptorBean;
@Override
public void afterSingletonsInstantiated() {
loadBalancerInterceptorBean = retryLoadBalancerInterceptor != null ?
retryLoadBalancerInterceptor :
loadBalancerInterceptor;
}
/** /**
* Adapt the {@link RestTemplate} beans that are annotated {@link LoadBalanced @LoadBalanced} and * Adapt the {@link RestTemplate} beans that are annotated {@link LoadBalanced @LoadBalanced} and
@ -140,7 +155,7 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(restTemplate.getInterceptors()); List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(restTemplate.getInterceptors());
int index = interceptors.indexOf(loadBalancerInterceptor); int index = loadBalancerInterceptorBean == null ? -1 : interceptors.indexOf(loadBalancerInterceptorBean);
index = index < 0 ? 0 : index; index = index < 0 ? 0 : index;
@ -157,4 +172,5 @@ public class DubboLoadBalancedRestTemplateAutoConfiguration implements BeanClass
public void setBeanClassLoader(ClassLoader classLoader) { public void setBeanClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader; this.classLoader = classLoader;
} }
} }

View File

@ -30,9 +30,9 @@ import org.springframework.cloud.alibaba.dubbo.metadata.repository.DubboServiceM
import org.springframework.cloud.alibaba.dubbo.metadata.resolver.DubboServiceBeanMetadataResolver; import org.springframework.cloud.alibaba.dubbo.metadata.resolver.DubboServiceBeanMetadataResolver;
import org.springframework.cloud.alibaba.dubbo.metadata.resolver.MetadataResolver; import org.springframework.cloud.alibaba.dubbo.metadata.resolver.MetadataResolver;
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory; import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory;
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigServiceExporter; import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceExporter;
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigServiceProxy; import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceProxy;
import org.springframework.cloud.alibaba.dubbo.service.PublishingDubboMetadataConfigService; import org.springframework.cloud.alibaba.dubbo.service.PublishingDubboMetadataService;
import org.springframework.cloud.alibaba.dubbo.util.JSONUtils; import org.springframework.cloud.alibaba.dubbo.util.JSONUtils;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -50,19 +50,19 @@ import java.util.function.Supplier;
*/ */
@Configuration @Configuration
@Import({DubboServiceMetadataRepository.class, @Import({DubboServiceMetadataRepository.class,
PublishingDubboMetadataConfigService.class, PublishingDubboMetadataService.class,
DubboMetadataConfigServiceExporter.class, DubboMetadataServiceExporter.class,
JSONUtils.class}) JSONUtils.class})
public class DubboMetadataAutoConfiguration { public class DubboMetadataAutoConfiguration {
@Autowired @Autowired
private PublishingDubboMetadataConfigService dubboMetadataConfigService; private PublishingDubboMetadataService dubboMetadataService;
@Autowired @Autowired
private MetadataResolver metadataResolver; private MetadataResolver metadataResolver;
@Autowired @Autowired
private DubboMetadataConfigServiceExporter dubboMetadataConfigServiceExporter; private DubboMetadataServiceExporter dubboMetadataConfigServiceExporter;
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ -77,8 +77,8 @@ public class DubboMetadataAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public DubboMetadataConfigServiceProxy dubboMetadataConfigServiceProxy(DubboGenericServiceFactory factory) { public DubboMetadataServiceProxy dubboMetadataConfigServiceProxy(DubboGenericServiceFactory factory) {
return new DubboMetadataConfigServiceProxy(factory); return new DubboMetadataServiceProxy(factory);
} }
// Event-Handling // Event-Handling
@ -101,7 +101,7 @@ public class DubboMetadataAutoConfiguration {
} }
private void publishServiceRestMetadata(ServiceBean serviceBean) { private void publishServiceRestMetadata(ServiceBean serviceBean) {
dubboMetadataConfigService.publishServiceRestMetadata(metadataResolver.resolveServiceRestMetadata(serviceBean)); dubboMetadataService.publishServiceRestMetadata(metadataResolver.resolveServiceRestMetadata(serviceBean));
} }
private void exportDubboMetadataConfigService() { private void exportDubboMetadataConfigService() {

View File

@ -18,7 +18,6 @@ package org.springframework.cloud.alibaba.dubbo.autoconfigure;
import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.spring.ServiceBean; import org.apache.dubbo.config.spring.ServiceBean;
import org.apache.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
import com.ecwid.consul.v1.agent.model.NewService; import com.ecwid.consul.v1.agent.model.NewService;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
@ -30,6 +29,8 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.cloud.alibaba.dubbo.metadata.repository.DubboServiceMetadataRepository;
import org.springframework.cloud.alibaba.dubbo.registry.event.ServiceInstancePreRegisteredEvent; import org.springframework.cloud.alibaba.dubbo.registry.event.ServiceInstancePreRegisteredEvent;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.Registration;
@ -40,7 +41,7 @@ import org.springframework.cloud.zookeeper.serviceregistry.ServiceInstanceRegist
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import java.util.List; import java.util.Collection;
import static org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_CONFIGURATION_CLASS_NAME; import static org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.CONSUL_AUTO_CONFIGURATION_CLASS_NAME;
import static org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.ZOOKEEPER_AUTO_CONFIGURATION_CLASS_NAME; import static org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.ZOOKEEPER_AUTO_CONFIGURATION_CLASS_NAME;
@ -65,18 +66,21 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
@Autowired @Autowired
private Registration registration; private Registration registration;
private volatile Integer webPort = null; private volatile Integer serverPort = null;
private volatile boolean registered = false; private volatile boolean registered = false;
@Autowired
private DubboServiceMetadataRepository repository;
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())") @Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
public Object getPort(ProceedingJoinPoint pjp) throws Throwable { public Object getPort(ProceedingJoinPoint pjp) throws Throwable {
return webPort != null ? webPort : pjp.proceed(); return serverPort != null ? serverPort : pjp.proceed();
} }
@EventListener(ServiceBeanExportedEvent.class) @EventListener(ApplicationStartedEvent.class)
public void onServiceBeanExported(ServiceBeanExportedEvent event) { public void onApplicationStarted() {
setWebPort(event.getServiceBean()); setServerPort();
register(); register();
} }
@ -90,18 +94,24 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
/** /**
* Set web port from {@link ServiceBean#getExportedUrls() exported URLs} if "rest" protocol is present. * Set web port from {@link ServiceBean#getExportedUrls() exported URLs} if "rest" protocol is present.
*
* @param serviceBean {@link ServiceBean}
*/ */
private void setWebPort(ServiceBean serviceBean) { private void setServerPort() {
if (webPort == null) { if (serverPort == null) {
List<URL> urls = serviceBean.getExportedUrls(); Collection<URL> urls = repository.getRegisteredUrls();
urls.stream() urls.stream()
.filter(url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol())) .filter(url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
.findFirst() .findFirst()
.ifPresent(url -> { .ifPresent(url -> {
webPort = url.getPort(); serverPort = url.getPort();
}); });
// If REST protocol is not present, use any applied port.
if (serverPort == null) {
urls.stream()
.findAny().ifPresent(url -> {
serverPort = url.getPort();
});
}
} }
} }
@ -114,7 +124,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
@EventListener(ServiceInstancePreRegisteredEvent.class) @EventListener(ServiceInstancePreRegisteredEvent.class)
public void onServiceInstancePreRegistered(ServiceInstancePreRegisteredEvent event) { public void onServiceInstancePreRegistered(ServiceInstancePreRegisteredEvent event) {
registration.setPort(webPort); registration.setPort(serverPort);
} }
@Override @Override

View File

@ -29,14 +29,15 @@ import org.springframework.cloud.alibaba.dubbo.http.matcher.RequestMetadataMatch
import org.springframework.cloud.alibaba.dubbo.metadata.DubboRestServiceMetadata; import org.springframework.cloud.alibaba.dubbo.metadata.DubboRestServiceMetadata;
import org.springframework.cloud.alibaba.dubbo.metadata.RequestMetadata; import org.springframework.cloud.alibaba.dubbo.metadata.RequestMetadata;
import org.springframework.cloud.alibaba.dubbo.metadata.ServiceRestMetadata; import org.springframework.cloud.alibaba.dubbo.metadata.ServiceRestMetadata;
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigService; import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataService;
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigServiceProxy; import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceProxy;
import org.springframework.cloud.alibaba.dubbo.util.JSONUtils; import org.springframework.cloud.alibaba.dubbo.util.JSONUtils;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.HttpRequest; import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.Collection; import java.util.Collection;
@ -88,7 +89,7 @@ public class DubboServiceMetadataRepository {
private DubboCloudProperties dubboCloudProperties; private DubboCloudProperties dubboCloudProperties;
@Autowired @Autowired
private DubboMetadataConfigServiceProxy dubboMetadataConfigServiceProxy; private DubboMetadataServiceProxy dubboMetadataConfigServiceProxy;
@Autowired @Autowired
private DiscoveryClient discoveryClient; private DiscoveryClient discoveryClient;
@ -255,13 +256,15 @@ public class DubboServiceMetadataRepository {
} }
private Set<ServiceRestMetadata> getServiceRestMetadataSet(String serviceName) { private Set<ServiceRestMetadata> getServiceRestMetadataSet(String serviceName) {
DubboMetadataConfigService dubboMetadataConfigService = dubboMetadataConfigServiceProxy.newProxy(serviceName); DubboMetadataService dubboMetadataService = dubboMetadataConfigServiceProxy.newProxy(serviceName);
Set<ServiceRestMetadata> metadata = Collections.emptySet(); Set<ServiceRestMetadata> metadata = Collections.emptySet();
try { try {
String serviceRestMetadataJsonConfig = dubboMetadataConfigService.getServiceRestMetadata(); String serviceRestMetadataJsonConfig = dubboMetadataService.getServiceRestMetadata();
if(StringUtils.hasText(serviceRestMetadataJsonConfig)) {
metadata = objectMapper.readValue(serviceRestMetadataJsonConfig, metadata = objectMapper.readValue(serviceRestMetadataJsonConfig,
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class)); TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class));
}
} catch (Exception e) { } catch (Exception e) {
if (logger.isErrorEnabled()) { if (logger.isErrorEnabled()) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);

View File

@ -21,16 +21,16 @@ import org.springframework.cloud.alibaba.dubbo.metadata.ServiceRestMetadata;
import java.util.Set; import java.util.Set;
/** /**
* Dubbo Metadata Configuration Service * Dubbo Metadata Service
* *
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/ */
public interface DubboMetadataConfigService { public interface DubboMetadataService {
/** /**
* Get The json content of {@link ServiceRestMetadata} {@link Set} * Get The json content of {@link ServiceRestMetadata} {@link Set}
* *
* @return the non-null String * @return <code>null</code> if present
*/ */
String getServiceRestMetadata(); String getServiceRestMetadata();
} }

View File

@ -25,17 +25,16 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
* {@link DubboMetadataConfigService} exporter * {@link DubboMetadataService} exporter
* *
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/ */
@Component @Component
public class DubboMetadataConfigServiceExporter { public class DubboMetadataServiceExporter {
private final Logger logger = LoggerFactory.getLogger(getClass()); private final Logger logger = LoggerFactory.getLogger(getClass());
@ -43,7 +42,7 @@ public class DubboMetadataConfigServiceExporter {
private ApplicationConfig applicationConfig; private ApplicationConfig applicationConfig;
@Autowired @Autowired
private PublishingDubboMetadataConfigService dubboMetadataConfigService; private DubboMetadataService dubboMetadataService;
@Autowired @Autowired
private Supplier<ProtocolConfig> protocolConfigSupplier; private Supplier<ProtocolConfig> protocolConfigSupplier;
@ -54,10 +53,10 @@ public class DubboMetadataConfigServiceExporter {
/** /**
* The ServiceConfig of DubboMetadataConfigService to be exported, can be nullable. * The ServiceConfig of DubboMetadataConfigService to be exported, can be nullable.
*/ */
private ServiceConfig<DubboMetadataConfigService> serviceConfig; private ServiceConfig<DubboMetadataService> serviceConfig;
/** /**
* export {@link DubboMetadataConfigService} as Dubbo service * export {@link DubboMetadataService} as Dubbo service
*/ */
public void export() { public void export() {
@ -65,21 +64,12 @@ public class DubboMetadataConfigServiceExporter {
return; return;
} }
if (StringUtils.isEmpty(dubboMetadataConfigService.getServiceRestMetadata())) {
// If there is no REST metadata, DubboMetadataConfigService will not be exported.
if (logger.isInfoEnabled()) {
logger.info("There is no REST metadata, the Dubbo service[{}] will not be exported.",
dubboMetadataConfigService.getClass().getName());
}
return;
}
serviceConfig = new ServiceConfig<>(); serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(DubboMetadataConfigService.class); serviceConfig.setInterface(DubboMetadataService.class);
// Use current Spring application name as the Dubbo Service version // Use current Spring application name as the Dubbo Service version
serviceConfig.setVersion(currentApplicationName); serviceConfig.setVersion(currentApplicationName);
serviceConfig.setRef(dubboMetadataConfigService); serviceConfig.setRef(dubboMetadataService);
serviceConfig.setApplication(applicationConfig); serviceConfig.setApplication(applicationConfig);
serviceConfig.setProtocol(protocolConfigSupplier.get()); serviceConfig.setProtocol(protocolConfigSupplier.get());
@ -92,7 +82,7 @@ public class DubboMetadataConfigServiceExporter {
/** /**
* unexport {@link DubboMetadataConfigService} * unexport {@link DubboMetadataService}
*/ */
public void unexport() { public void unexport() {

View File

@ -22,14 +22,14 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/** /**
* {@link DubboMetadataConfigService} {@link InvocationHandler} * {@link DubboMetadataService} {@link InvocationHandler}
* *
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/ */
class DubboMetadataConfigServiceInvocationHandler implements InvocationHandler { class DubboMetadataServiceInvocationHandler implements InvocationHandler {
/** /**
* The method name of {@link DubboMetadataConfigService#getServiceRestMetadata()} * The method name of {@link DubboMetadataService#getServiceRestMetadata()}
*/ */
private static final String METHOD_NAME = "getServiceRestMetadata"; private static final String METHOD_NAME = "getServiceRestMetadata";
@ -39,8 +39,8 @@ class DubboMetadataConfigServiceInvocationHandler implements InvocationHandler {
private final GenericService genericService; private final GenericService genericService;
public DubboMetadataConfigServiceInvocationHandler(String serviceName, DubboGenericServiceFactory dubboGenericServiceFactory) { public DubboMetadataServiceInvocationHandler(String serviceName, DubboGenericServiceFactory dubboGenericServiceFactory) {
this.genericService = dubboGenericServiceFactory.create(serviceName, DubboMetadataConfigService.class); this.genericService = dubboGenericServiceFactory.create(serviceName, DubboMetadataService.class);
} }
@Override @Override

View File

@ -21,27 +21,27 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import static java.lang.reflect.Proxy.newProxyInstance; import static java.lang.reflect.Proxy.newProxyInstance;
/** /**
* The proxy of {@link DubboMetadataConfigService} * The proxy of {@link DubboMetadataService}
*/ */
public class DubboMetadataConfigServiceProxy implements BeanClassLoaderAware { public class DubboMetadataServiceProxy implements BeanClassLoaderAware {
private final DubboGenericServiceFactory dubboGenericServiceFactory; private final DubboGenericServiceFactory dubboGenericServiceFactory;
private ClassLoader classLoader; private ClassLoader classLoader;
public DubboMetadataConfigServiceProxy(DubboGenericServiceFactory dubboGenericServiceFactory) { public DubboMetadataServiceProxy(DubboGenericServiceFactory dubboGenericServiceFactory) {
this.dubboGenericServiceFactory = dubboGenericServiceFactory; this.dubboGenericServiceFactory = dubboGenericServiceFactory;
} }
/** /**
* New proxy instance of {@link DubboMetadataConfigService} via the specified service name * New proxy instance of {@link DubboMetadataService} via the specified service name
* *
* @param serviceName the service name * @param serviceName the service name
* @return a {@link DubboMetadataConfigService} proxy * @return a {@link DubboMetadataService} proxy
*/ */
public DubboMetadataConfigService newProxy(String serviceName) { public DubboMetadataService newProxy(String serviceName) {
return (DubboMetadataConfigService) newProxyInstance(classLoader, new Class[]{DubboMetadataConfigService.class}, return (DubboMetadataService) newProxyInstance(classLoader, new Class[]{DubboMetadataService.class},
new DubboMetadataConfigServiceInvocationHandler(serviceName, dubboGenericServiceFactory)); new DubboMetadataServiceInvocationHandler(serviceName, dubboGenericServiceFactory));
} }
@Override @Override

View File

@ -27,11 +27,11 @@ import java.util.Set;
import static org.springframework.util.ObjectUtils.isEmpty; import static org.springframework.util.ObjectUtils.isEmpty;
/** /**
* Publishing {@link DubboMetadataConfigService} implementation * Publishing {@link DubboMetadataService} implementation
* *
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a> * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/ */
public class PublishingDubboMetadataConfigService implements DubboMetadataConfigService { public class PublishingDubboMetadataService implements DubboMetadataService {
/** /**
* A Map to store REST metadata temporary, its' key is the special service name for a Dubbo service, * A Map to store REST metadata temporary, its' key is the special service name for a Dubbo service,

View File

@ -0,0 +1,7 @@
# Dubbo Endpoints Default Properties is loaded by @PropertySource with low order,
# Set enabled for Dubbo Endpoints
management.endpoint.dubborestmetadata.enabled = true
# "management.endpoints.web.base-path" should not be configured in this file
# Re-defines path-mapping of Dubbo Web Endpoints
management.endpoints.web.path-mapping.dubborestmetadata = dubbo/rest/metadata

View File

@ -6,10 +6,11 @@ org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceRegistrationNo
org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboLoadBalancedRestTemplateAutoConfiguration,\ org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboLoadBalancedRestTemplateAutoConfiguration,\
org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceAutoConfiguration org.springframework.cloud.alibaba.dubbo.autoconfigure.DubboServiceAutoConfiguration
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
org.springframework.cloud.alibaba.dubbo.actuate.DubboMetadataEndpointAutoConfiguration
org.springframework.context.ApplicationContextInitializer=\ org.springframework.context.ApplicationContextInitializer=\
org.springframework.cloud.alibaba.dubbo.context.DubboServiceRegistrationApplicationContextInitializer org.springframework.cloud.alibaba.dubbo.context.DubboServiceRegistrationApplicationContextInitializer
org.springframework.boot.env.EnvironmentPostProcessor=\ org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.cloud.alibaba.dubbo.env.DubboNonWebApplicationEnvironmentPostProcessor org.springframework.cloud.alibaba.dubbo.env.DubboNonWebApplicationEnvironmentPostProcessor