Merge remote-tracking branch 'upstream/master' into binder-dev

pull/611/head
fangjian0423
commit 52da6f43c4

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId> <artifactId>spring-cloud-build</artifactId>
<version>2.1.2.RELEASE</version> <version>2.1.3.RELEASE</version>
<relativePath/> <relativePath/>
</parent> </parent>
@ -70,11 +70,11 @@
<properties> <properties>
<!-- Dependency Versions --> <!-- Dependency Versions -->
<spring-cloud-commons.version>2.1.0.RELEASE</spring-cloud-commons.version> <spring-cloud-commons.version>2.1.1.RELEASE</spring-cloud-commons.version>
<spring-cloud-netflix.version>2.1.0.RELEASE</spring-cloud-netflix.version> <spring-cloud-netflix.version>2.1.1.RELEASE</spring-cloud-netflix.version>
<spring-cloud-openfeign.version>2.1.0.RELEASE</spring-cloud-openfeign.version> <spring-cloud-openfeign.version>2.1.1.RELEASE</spring-cloud-openfeign.version>
<spring-cloud-bus.version>2.1.0.RELEASE</spring-cloud-bus.version> <spring-cloud-bus.version>2.1.1.RELEASE</spring-cloud-bus.version>
<spring-cloud-gateway.version>2.1.0.RELEASE</spring-cloud-gateway.version> <spring-cloud-gateway.version>2.1.1.RELEASE</spring-cloud-gateway.version>
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<javax-servlet-api>3.0</javax-servlet-api> <javax-servlet-api>3.0</javax-servlet-api>

@ -6,7 +6,7 @@
<parent> <parent>
<artifactId>spring-cloud-dependencies-parent</artifactId> <artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<version>2.1.2.RELEASE</version> <version>2.1.3.RELEASE</version>
<relativePath/> <relativePath/>
</parent> </parent>

@ -15,8 +15,8 @@
<properties> <properties>
<dubbo.version>2.7.1</dubbo.version> <dubbo.version>2.7.1</dubbo.version>
<spring-cloud-zookeeper.version>2.1.0.RELEASE</spring-cloud-zookeeper.version> <spring-cloud-zookeeper.version>2.1.1.RELEASE</spring-cloud-zookeeper.version>
<spring-cloud-consul.version>2.1.0.RELEASE</spring-cloud-consul.version> <spring-cloud-consul.version>2.1.1.RELEASE</spring-cloud-consul.version>
<curator.version>4.0.1</curator.version> <curator.version>4.0.1</curator.version>
</properties> </properties>
@ -181,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>

@ -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();
}
}

@ -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();
}
}

@ -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;
} }
} }

@ -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() {

@ -30,6 +30,7 @@ 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.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;
@ -77,6 +78,10 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
@EventListener(ServiceBeanExportedEvent.class) @EventListener(ServiceBeanExportedEvent.class)
public void onServiceBeanExported(ServiceBeanExportedEvent event) { public void onServiceBeanExported(ServiceBeanExportedEvent event) {
setWebPort(event.getServiceBean()); setWebPort(event.getServiceBean());
}
@EventListener(ApplicationStartedEvent.class)
public void onApplicationStarted() {
register(); register();
} }

@ -29,8 +29,8 @@ 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;
@ -88,7 +88,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,11 +255,11 @@ 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();
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) {

@ -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();
} }

@ -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() {

@ -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

@ -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

@ -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,

@ -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

@ -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

@ -25,8 +25,8 @@
<properties> <properties>
<dubbo.version>2.7.0</dubbo.version> <dubbo.version>2.7.0</dubbo.version>
<spring-cloud-zookeeper.version>2.1.0.RELEASE</spring-cloud-zookeeper.version> <spring-cloud-zookeeper.version>2.1.1.RELEASE</spring-cloud-zookeeper.version>
<spring-cloud-consul.version>2.1.0.RELEASE</spring-cloud-consul.version> <spring-cloud-consul.version>2.1.1.RELEASE</spring-cloud-consul.version>
<curator.version>4.0.1</curator.version> <curator.version>4.0.1</curator.version>
</properties> </properties>
@ -96,87 +96,57 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
</dependencies> <!-- Spring Cloud Nacos Service Discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- Spring Cloud Eureka Service Discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<profiles> <!-- Spring Cloud Zookeeper Service Discovery -->
<dependency>
<!-- Nacos --> <groupId>org.springframework.cloud</groupId>
<profile> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
<id>nacos</id> <version>${spring-cloud-zookeeper.version}</version>
<activation> <exclusions>
<activeByDefault>true</activeByDefault> <exclusion>
</activation>
<dependencies>
<!-- Nacos Service Discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>eureka</id>
<dependencies>
<!-- Eureka Service Discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
</profile>
<!-- Zookeeper -->
<profile>
<id>zookeeper</id>
<dependencies>
<!-- Zookeeper Service Discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
<version>${spring-cloud-zookeeper.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId> <groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId> <artifactId>zookeeper</artifactId>
<version>3.4.12</version> </exclusion>
<optional>true</optional> </exclusions>
<exclusions> </dependency>
<exclusion>
<groupId>org.slf4j</groupId> <dependency>
<artifactId>slf4j-log4j12</artifactId> <groupId>org.apache.zookeeper</groupId>
</exclusion> <artifactId>zookeeper</artifactId>
</exclusions> <version>3.4.12</version>
</dependency> <optional>true</optional>
<exclusions>
<dependency> <exclusion>
<groupId>org.apache.curator</groupId> <groupId>org.slf4j</groupId>
<artifactId>curator-framework</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>${curator.version}</version> </exclusion>
</dependency> </exclusions>
</dependencies> </dependency>
</profile>
<dependency>
<profile> <groupId>org.apache.curator</groupId>
<id>consul</id> <artifactId>curator-framework</artifactId>
<dependencies> <version>${curator.version}</version>
<!-- Spring Cloud Consul --> </dependency>
<dependency>
<groupId>org.springframework.cloud</groupId> <!-- Spring Cloud Consul Service Discovery -->
<artifactId>spring-cloud-starter-consul-discovery</artifactId> <dependency>
<version>${spring-cloud-consul.version}</version> <groupId>org.springframework.cloud</groupId>
</dependency> <artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependencies> <version>${spring-cloud-consul.version}</version>
</profile> </dependency>
</dependencies>
</profiles>
<build> <build>
<plugins> <plugins>

@ -21,17 +21,23 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- Sample API --> <!-- Spring Cloud Open Feign -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dubbo-sample-api</artifactId> <artifactId>spring-cloud-starter-openfeign</artifactId>
<version>${project.version}</version>
</dependency> </dependency>
<!-- Spring Cloud Open Feign --> <!-- Spring Retry -->
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<!-- Sample API -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId> <artifactId>spring-cloud-dubbo-sample-api</artifactId>
<version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>

@ -26,6 +26,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.alibaba.dubbo.annotation.DubboTransported; import org.springframework.cloud.alibaba.dubbo.annotation.DubboTransported;
import org.springframework.cloud.alibaba.dubbo.service.RestService; import org.springframework.cloud.alibaba.dubbo.service.RestService;
import org.springframework.cloud.alibaba.dubbo.service.User; import org.springframework.cloud.alibaba.dubbo.service.User;
import org.springframework.cloud.alibaba.dubbo.service.UserService;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@ -53,6 +54,9 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
@EnableFeignClients @EnableFeignClients
public class DubboSpringCloudConsumerBootstrap { public class DubboSpringCloudConsumerBootstrap {
@Reference
private UserService userService;
@Reference(version = "1.0.0", protocol = "dubbo") @Reference(version = "1.0.0", protocol = "dubbo")
private RestService restService; private RestService restService;
@ -119,7 +123,28 @@ public class DubboSpringCloudConsumerBootstrap {
} }
@Bean @Bean
public ApplicationRunner paramRunner() { public ApplicationRunner userServiceRunner() {
return arguments -> {
User user = new User();
user.setId(1L);
user.setName("小马哥");
user.setAge(33);
// save User
System.out.printf("UserService.save(%s) : %s\n", user, userService.save(user));
// find all Users
System.out.printf("UserService.findAll() : %s\n", user, userService.findAll());
// remove User
System.out.printf("UserService.remove(%d) : %s\n", user.getId(), userService.remove(user.getId()));
};
}
@Bean
public ApplicationRunner callRunner() {
return arguments -> { return arguments -> {
// To call /path-variables // To call /path-variables

@ -0,0 +1,47 @@
/*
* 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.service;
import org.apache.dubbo.config.annotation.Service;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* In-Memory {@link UserService} implementation
*/
@Service(protocol = "dubbo")
public class InMemoryUserService implements UserService {
private Map<Long, User> usersRepository = new HashMap<>();
@Override
public boolean save(User user) {
return usersRepository.put(user.getId(), user) == null;
}
@Override
public boolean remove(Long userId) {
return usersRepository.remove(userId) != null;
}
@Override
public Collection<User> findAll() {
return usersRepository.values();
}
}

@ -16,6 +16,12 @@
<dependencies> <dependencies>
<!-- Production Ready features -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>

@ -0,0 +1,47 @@
/*
* 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.service;
import org.apache.dubbo.config.annotation.Service;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* In-Memory {@link UserService} implementation
*/
@Service(protocol = "dubbo")
public class InMemoryUserService implements UserService {
private Map<Long, User> usersRepository = new HashMap<>();
@Override
public boolean save(User user) {
return usersRepository.put(user.getId(), user) == null;
}
@Override
public boolean remove(Long userId) {
return usersRepository.remove(userId) != null;
}
@Override
public Collection<User> findAll() {
return usersRepository.values();
}
}

@ -16,4 +16,10 @@ feign:
enabled: true enabled: true
server: server:
port: 8080 port: 8080
management:
endpoints:
web:
exposure:
include: dubborestmetadata

@ -0,0 +1,33 @@
/*
* 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.service;
import java.util.Collection;
/**
* {@link User} Service
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
*/
public interface UserService {
boolean save(User user);
boolean remove(Long userId);
Collection<User> findAll();
}
Loading…
Cancel
Save