mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #546 from mercyblitz/master
Dubbo Spring Cloud Updates
This commit is contained in:
commit
e7a1dfd46c
@ -181,6 +181,13 @@
|
||||
<version>${dubbo.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Dubbo Spring Boot Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-actuator</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Netty -->
|
||||
<dependency>
|
||||
<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();
|
||||
}
|
||||
}
|
@ -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.MetadataResolver;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboGenericServiceFactory;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigServiceExporter;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigServiceProxy;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.PublishingDubboMetadataConfigService;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceExporter;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceProxy;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.PublishingDubboMetadataService;
|
||||
import org.springframework.cloud.alibaba.dubbo.util.JSONUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -50,19 +50,19 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
@Configuration
|
||||
@Import({DubboServiceMetadataRepository.class,
|
||||
PublishingDubboMetadataConfigService.class,
|
||||
DubboMetadataConfigServiceExporter.class,
|
||||
PublishingDubboMetadataService.class,
|
||||
DubboMetadataServiceExporter.class,
|
||||
JSONUtils.class})
|
||||
public class DubboMetadataAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private PublishingDubboMetadataConfigService dubboMetadataConfigService;
|
||||
private PublishingDubboMetadataService dubboMetadataService;
|
||||
|
||||
@Autowired
|
||||
private MetadataResolver metadataResolver;
|
||||
|
||||
@Autowired
|
||||
private DubboMetadataConfigServiceExporter dubboMetadataConfigServiceExporter;
|
||||
private DubboMetadataServiceExporter dubboMetadataConfigServiceExporter;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ -77,8 +77,8 @@ public class DubboMetadataAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public DubboMetadataConfigServiceProxy dubboMetadataConfigServiceProxy(DubboGenericServiceFactory factory) {
|
||||
return new DubboMetadataConfigServiceProxy(factory);
|
||||
public DubboMetadataServiceProxy dubboMetadataConfigServiceProxy(DubboGenericServiceFactory factory) {
|
||||
return new DubboMetadataServiceProxy(factory);
|
||||
}
|
||||
|
||||
// Event-Handling
|
||||
@ -101,7 +101,7 @@ public class DubboMetadataAutoConfiguration {
|
||||
}
|
||||
|
||||
private void publishServiceRestMetadata(ServiceBean serviceBean) {
|
||||
dubboMetadataConfigService.publishServiceRestMetadata(metadataResolver.resolveServiceRestMetadata(serviceBean));
|
||||
dubboMetadataService.publishServiceRestMetadata(metadataResolver.resolveServiceRestMetadata(serviceBean));
|
||||
}
|
||||
|
||||
private void exportDubboMetadataConfigService() {
|
||||
|
@ -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.RequestMetadata;
|
||||
import org.springframework.cloud.alibaba.dubbo.metadata.ServiceRestMetadata;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigService;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataConfigServiceProxy;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataService;
|
||||
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceProxy;
|
||||
import org.springframework.cloud.alibaba.dubbo.util.JSONUtils;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
@ -88,7 +88,7 @@ public class DubboServiceMetadataRepository {
|
||||
private DubboCloudProperties dubboCloudProperties;
|
||||
|
||||
@Autowired
|
||||
private DubboMetadataConfigServiceProxy dubboMetadataConfigServiceProxy;
|
||||
private DubboMetadataServiceProxy dubboMetadataConfigServiceProxy;
|
||||
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
@ -255,11 +255,11 @@ public class DubboServiceMetadataRepository {
|
||||
}
|
||||
|
||||
private Set<ServiceRestMetadata> getServiceRestMetadataSet(String serviceName) {
|
||||
DubboMetadataConfigService dubboMetadataConfigService = dubboMetadataConfigServiceProxy.newProxy(serviceName);
|
||||
DubboMetadataService dubboMetadataService = dubboMetadataConfigServiceProxy.newProxy(serviceName);
|
||||
|
||||
Set<ServiceRestMetadata> metadata = Collections.emptySet();
|
||||
try {
|
||||
String serviceRestMetadataJsonConfig = dubboMetadataConfigService.getServiceRestMetadata();
|
||||
String serviceRestMetadataJsonConfig = dubboMetadataService.getServiceRestMetadata();
|
||||
metadata = objectMapper.readValue(serviceRestMetadataJsonConfig,
|
||||
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class));
|
||||
} catch (Exception e) {
|
||||
|
@ -21,16 +21,16 @@ import org.springframework.cloud.alibaba.dubbo.metadata.ServiceRestMetadata;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Dubbo Metadata Configuration Service
|
||||
* Dubbo Metadata Service
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public interface DubboMetadataConfigService {
|
||||
public interface DubboMetadataService {
|
||||
|
||||
/**
|
||||
* Get The json content of {@link ServiceRestMetadata} {@link Set}
|
||||
*
|
||||
* @return the non-null String
|
||||
* @return <code>null</code> if present
|
||||
*/
|
||||
String getServiceRestMetadata();
|
||||
}
|
@ -25,17 +25,16 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* {@link DubboMetadataConfigService} exporter
|
||||
* {@link DubboMetadataService} exporter
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@Component
|
||||
public class DubboMetadataConfigServiceExporter {
|
||||
public class DubboMetadataServiceExporter {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@ -43,7 +42,7 @@ public class DubboMetadataConfigServiceExporter {
|
||||
private ApplicationConfig applicationConfig;
|
||||
|
||||
@Autowired
|
||||
private PublishingDubboMetadataConfigService dubboMetadataConfigService;
|
||||
private DubboMetadataService dubboMetadataService;
|
||||
|
||||
@Autowired
|
||||
private Supplier<ProtocolConfig> protocolConfigSupplier;
|
||||
@ -54,10 +53,10 @@ public class DubboMetadataConfigServiceExporter {
|
||||
/**
|
||||
* 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() {
|
||||
|
||||
@ -65,21 +64,12 @@ public class DubboMetadataConfigServiceExporter {
|
||||
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.setInterface(DubboMetadataConfigService.class);
|
||||
serviceConfig.setInterface(DubboMetadataService.class);
|
||||
// Use current Spring application name as the Dubbo Service version
|
||||
serviceConfig.setVersion(currentApplicationName);
|
||||
serviceConfig.setRef(dubboMetadataConfigService);
|
||||
serviceConfig.setRef(dubboMetadataService);
|
||||
serviceConfig.setApplication(applicationConfig);
|
||||
serviceConfig.setProtocol(protocolConfigSupplier.get());
|
||||
|
||||
@ -92,7 +82,7 @@ public class DubboMetadataConfigServiceExporter {
|
||||
|
||||
|
||||
/**
|
||||
* unexport {@link DubboMetadataConfigService}
|
||||
* unexport {@link DubboMetadataService}
|
||||
*/
|
||||
public void unexport() {
|
||||
|
@ -22,14 +22,14 @@ import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* {@link DubboMetadataConfigService} {@link InvocationHandler}
|
||||
* {@link DubboMetadataService} {@link InvocationHandler}
|
||||
*
|
||||
* @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";
|
||||
|
||||
@ -39,8 +39,8 @@ class DubboMetadataConfigServiceInvocationHandler implements InvocationHandler {
|
||||
|
||||
private final GenericService genericService;
|
||||
|
||||
public DubboMetadataConfigServiceInvocationHandler(String serviceName, DubboGenericServiceFactory dubboGenericServiceFactory) {
|
||||
this.genericService = dubboGenericServiceFactory.create(serviceName, DubboMetadataConfigService.class);
|
||||
public DubboMetadataServiceInvocationHandler(String serviceName, DubboGenericServiceFactory dubboGenericServiceFactory) {
|
||||
this.genericService = dubboGenericServiceFactory.create(serviceName, DubboMetadataService.class);
|
||||
}
|
||||
|
||||
@Override
|
@ -21,27 +21,27 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
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 ClassLoader classLoader;
|
||||
|
||||
public DubboMetadataConfigServiceProxy(DubboGenericServiceFactory dubboGenericServiceFactory) {
|
||||
public DubboMetadataServiceProxy(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
|
||||
* @return a {@link DubboMetadataConfigService} proxy
|
||||
* @return a {@link DubboMetadataService} proxy
|
||||
*/
|
||||
public DubboMetadataConfigService newProxy(String serviceName) {
|
||||
return (DubboMetadataConfigService) newProxyInstance(classLoader, new Class[]{DubboMetadataConfigService.class},
|
||||
new DubboMetadataConfigServiceInvocationHandler(serviceName, dubboGenericServiceFactory));
|
||||
public DubboMetadataService newProxy(String serviceName) {
|
||||
return (DubboMetadataService) newProxyInstance(classLoader, new Class[]{DubboMetadataService.class},
|
||||
new DubboMetadataServiceInvocationHandler(serviceName, dubboGenericServiceFactory));
|
||||
}
|
||||
|
||||
@Override
|
@ -27,11 +27,11 @@ import java.util.Set;
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
|
||||
/**
|
||||
* Publishing {@link DubboMetadataConfigService} implementation
|
||||
* Publishing {@link DubboMetadataService} implementation
|
||||
*
|
||||
* @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,
|
@ -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.DubboServiceAutoConfiguration
|
||||
|
||||
org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration=\
|
||||
org.springframework.cloud.alibaba.dubbo.actuate.DubboMetadataEndpointAutoConfiguration
|
||||
|
||||
org.springframework.context.ApplicationContextInitializer=\
|
||||
org.springframework.cloud.alibaba.dubbo.context.DubboServiceRegistrationApplicationContextInitializer
|
||||
|
||||
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.alibaba.dubbo.env.DubboNonWebApplicationEnvironmentPostProcessor
|
@ -16,6 +16,12 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Production Ready features -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
@ -16,4 +16,10 @@ feign:
|
||||
enabled: true
|
||||
|
||||
server:
|
||||
port: 8080
|
||||
port: 8080
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: dubborestmetadata
|
Loading…
x
Reference in New Issue
Block a user