Apache Dubbo is a powerful RPC framework for building enterprise-grade microservices with service discovery, load balancing, and fault tolerance.
—
Apache Dubbo's metadata management system provides comprehensive service metadata collection, storage, and retrieval capabilities. It supports service discovery optimization, contract management, and runtime service introspection through configurable metadata backends.
Central metadata storage and management for service definitions and configurations.
/**
* Metadata report interface for storing and retrieving service metadata
*/
@SPI("zookeeper")
public interface MetadataReport {
/**
* Store provider metadata
* @param providerMetaDataIdentifier Provider metadata identifier
* @param serviceDefinition Service definition
*/
void storeProviderMetadata(MetadataIdentifier providerMetaDataIdentifier,
String serviceDefinition);
/**
* Store consumer metadata
* @param consumerMetadataIdentifier Consumer metadata identifier
* @param serviceParameterString Service parameters
*/
void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier,
String serviceParameterString);
/**
* Save service metadata
* @param serviceMetadataIdentifier Service metadata identifier
* @param url Service URL
*/
void saveServiceMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier, URL url);
/**
* Remove service metadata
* @param serviceMetadataIdentifier Service metadata identifier
*/
void removeServiceMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier);
/**
* Get exported URLs
* @param serviceMetadataIdentifier Service metadata identifier
* @return List of exported URLs
*/
List<String> getExportedURLs(ServiceMetadataIdentifier serviceMetadataIdentifier);
/**
* Save subscribed data
* @param subscriberMetadataIdentifier Subscriber metadata identifier
* @param urls Subscribed URLs
*/
void saveSubscribedData(SubscriberMetadataIdentifier subscriberMetadataIdentifier,
Set<String> urls);
/**
* Get subscribed URLs
* @param subscriberMetadataIdentifier Subscriber metadata identifier
* @return Subscribed URLs
*/
List<String> getSubscribedURLs(SubscriberMetadataIdentifier subscriberMetadataIdentifier);
/**
* Get service definition
* @param metadataIdentifier Metadata identifier
* @return Service definition
*/
String getServiceDefinition(MetadataIdentifier metadataIdentifier);
}
/**
* Metadata report factory
*/
@SPI("zookeeper")
public interface MetadataReportFactory {
/**
* Create metadata report instance
* @param url Configuration URL
* @return Metadata report instance
*/
MetadataReport getMetadataReport(URL url);
}Configuration for metadata reporting and management.
/**
* Metadata report configuration
*/
public class MetadataReportConfig extends AbstractConfig {
public MetadataReportConfig();
/** Set metadata center address */
public void setAddress(String address);
public String getAddress();
/** Set metadata center username */
public void setUsername(String username);
public String getUsername();
/** Set metadata center password */
public void setPassword(String password);
public String getPassword();
/** Set connection timeout */
public void setTimeout(Integer timeout);
public Integer getTimeout();
/** Set retry times */
public void setRetryTimes(Integer retryTimes);
public Integer getRetryTimes();
/** Set retry period */
public void setRetryPeriod(Integer retryPeriod);
public Integer getRetryPeriod();
/** Set cycle report */
public void setCycleReport(Boolean cycleReport);
public Boolean getCycleReport();
/** Set sync report */
public void setSyncReport(Boolean syncReport);
public Boolean getSyncReport();
/** Set group */
public void setGroup(String group);
public String getGroup();
/** Set cluster */
public void setCluster(String cluster);
public String getCluster();
/** Set registry */
public void setRegistry(String registry);
public String getRegistry();
/** Set file */
public void setFile(String file);
public String getFile();
/** Set parameters */
public void setParameters(Map<String, String> parameters);
public Map<String, String> getParameters();
}Usage Examples:
import org.apache.dubbo.config.MetadataReportConfig;
// Configure metadata report
MetadataReportConfig metadataReport = new MetadataReportConfig();
metadataReport.setAddress("zookeeper://127.0.0.1:2181");
metadataReport.setGroup("dubbo");
metadataReport.setTimeout(5000);
metadataReport.setRetryTimes(3);
// Add to bootstrap
DubboBootstrap.getInstance()
.metadataReport(metadataReport)
.start();Service metadata representation and management.
/**
* Service metadata containing service definition and configuration
*/
public class ServiceMetadata {
public ServiceMetadata();
public ServiceMetadata(String serviceName);
/** Get service name */
public String getServiceName();
public void setServiceName(String serviceName);
/** Get service version */
public String getVersion();
public void setVersion(String version);
/** Get service group */
public String getGroup();
public void setGroup(String group);
/** Get service type */
public String getServiceType();
public void setServiceType(String serviceType);
/** Get target service */
public Object getTarget();
public void setTarget(Object target);
/** Get service interface */
public Class<?> getServiceInterfaceClass();
public void setServiceInterfaceClass(Class<?> serviceInterfaceClass);
/** Generate service key */
public String generateServiceKey();
/** Get method metadata */
public List<MethodMetadata> getMethods();
public void setMethods(List<MethodMetadata> methods);
/** Add method metadata */
public void addMethod(MethodMetadata methodMetadata);
}
/**
* Method metadata for service methods
*/
public class MethodMetadata {
public MethodMetadata();
/** Get method name */
public String getMethodName();
public void setMethodName(String methodName);
/** Get parameter types */
public String[] getParameterTypes();
public void setParameterTypes(String[] parameterTypes);
/** Get return type */
public String getReturnType();
public void setReturnType(String returnType);
/** Get method signature */
public String getMethodSignature();
/** Get annotations */
public Map<String, Object> getAnnotations();
public void setAnnotations(Map<String, Object> annotations);
}Unique identifiers for different types of metadata.
/**
* Base metadata identifier
*/
public class MetadataIdentifier {
public MetadataIdentifier(String serviceInterface, String version, String group,
String side, String application);
/** Get service interface */
public String getServiceInterface();
/** Get version */
public String getVersion();
/** Get group */
public String getGroup();
/** Get side (provider/consumer) */
public String getSide();
/** Get application */
public String getApplication();
/** Get unique key */
public String getUniqueKey(KeyTypeEnum keyType);
/** Get identifier key */
public String getIdentifierKey();
}
/**
* Service metadata identifier
*/
public class ServiceMetadataIdentifier extends MetadataIdentifier {
public ServiceMetadataIdentifier(String serviceInterface, String version, String group,
String side, String revision, String protocol);
/** Get revision */
public String getRevision();
/** Get protocol */
public String getProtocol();
}
/**
* Subscriber metadata identifier
*/
public class SubscriberMetadataIdentifier extends MetadataIdentifier {
public SubscriberMetadataIdentifier(String application, String revision);
/** Get revision */
public String getRevision();
}Structured service definition for metadata storage.
/**
* Full service definition including all metadata
*/
public class FullServiceDefinition {
public FullServiceDefinition();
/** Get canonical name */
public String getCanonicalName();
public void setCanonicalName(String canonicalName);
/** Get code source */
public String getCodeSource();
public void setCodeSource(String codeSource);
/** Get methods */
public List<MethodDefinition> getMethods();
public void setMethods(List<MethodDefinition> methods);
/** Get types */
public List<TypeDefinition> getTypes();
public void setTypes(List<TypeDefinition> types);
/** Get annotations */
public Map<String, Object> getAnnotations();
public void setAnnotations(Map<String, Object> annotations);
/** Get parameters */
public Map<String, String> getParameters();
public void setParameters(Map<String, String> parameters);
}
/**
* Method definition within service
*/
public class MethodDefinition {
public MethodDefinition();
/** Get method name */
public String getName();
public void setName(String name);
/** Get parameter types */
public String[] getParameterTypes();
public void setParameterTypes(String[] parameterTypes);
/** Get return type */
public String getReturnType();
public void setReturnType(String returnType);
/** Get annotations */
public Map<String, Object> getAnnotations();
public void setAnnotations(Map<String, Object> annotations);
}
/**
* Type definition for complex types
*/
public class TypeDefinition {
public TypeDefinition();
public TypeDefinition(String type);
/** Get type identifier */
public String getId();
public void setId(String id);
/** Get type name */
public String getType();
public void setType(String type);
/** Get type properties */
public List<String> getProperties();
public void setProperties(List<String> properties);
/** Get items (for collections) */
public String getItems();
public void setItems(String items);
}Service for metadata operations and queries.
/**
* Metadata service for runtime metadata operations
*/
public interface MetadataService {
/** Service name for metadata service */
String SERVICE_NAME = "org.apache.dubbo.metadata.MetadataService";
/**
* Get service definition
* @param interfaceName Service interface name
* @param version Service version
* @param group Service group
* @return Service definition
*/
String getServiceDefinition(String interfaceName, String version, String group);
/**
* Get service definition by key
* @param serviceKey Service key
* @return Service definition
*/
String getServiceDefinition(String serviceKey);
/**
* Get exported URLs
* @param serviceInterface Service interface
* @param group Service group
* @param version Service version
* @param protocol Protocol filter
* @return Exported URLs
*/
SortedSet<String> getExportedURLs(String serviceInterface, String group,
String version, String protocol);
/**
* Get exported URLs
* @return All exported URLs
*/
SortedSet<String> getExportedURLs();
/**
* Get subscribed URLs
* @return Subscribed URLs
*/
SortedSet<String> getSubscribedURLs();
/**
* Get metadata version
* @return Metadata version
*/
String getMetadataVersion();
/**
* Get metadata info
* @param revision Metadata revision
* @return Metadata info
*/
MetadataInfo getMetadataInfo(String revision);
}
/**
* Metadata info containing service metadata
*/
public class MetadataInfo {
public MetadataInfo();
public MetadataInfo(String app);
/** Get application name */
public String getApp();
public void setApp(String app);
/** Get revision */
public String getRevision();
public void setRevision(String revision);
/** Get services */
public Map<String, ServiceInfo> getServices();
public void setServices(Map<String, ServiceInfo> services);
/** Add service */
public void addService(ServiceInfo serviceInfo);
/** Get service */
public ServiceInfo getService(String serviceKey);
}Usage Examples:
import org.apache.dubbo.metadata.MetadataService;
// Get metadata service reference
ReferenceConfig<MetadataService> metadataReference = new ReferenceConfig<>();
metadataReference.setInterface(MetadataService.class);
metadataReference.setGroup("dubbo");
metadataReference.setVersion("1.0.0");
MetadataService metadataService = metadataReference.get();
// Query service definition
String definition = metadataService.getServiceDefinition(
"com.example.GreeterService", "1.0.0", "default");
// Get exported URLs
SortedSet<String> exportedUrls = metadataService.getExportedURLs();
// Get specific service URLs
SortedSet<String> serviceUrls = metadataService.getExportedURLs(
"com.example.GreeterService", "default", "1.0.0", "dubbo");Different storage backends for metadata persistence.
ZooKeeper Metadata Report:
// ZooKeeper-based metadata storage
MetadataReportConfig metadataReport = new MetadataReportConfig();
metadataReport.setAddress("zookeeper://127.0.0.1:2181");
metadataReport.setGroup("dubbo");Nacos Metadata Report:
// Nacos-based metadata storage
MetadataReportConfig metadataReport = new MetadataReportConfig();
metadataReport.setAddress("nacos://127.0.0.1:8848");
metadataReport.setGroup("DEFAULT_GROUP");
metadataReport.setUsername("nacos");
metadataReport.setPassword("nacos");Redis Metadata Report:
// Redis-based metadata storage
MetadataReportConfig metadataReport = new MetadataReportConfig();
metadataReport.setAddress("redis://127.0.0.1:6379");
metadataReport.setGroup("dubbo");Configuration for metadata synchronization behavior.
/**
* Metadata synchronization configuration
*/
public class MetadataSyncConfig {
/** Enable sync report */
private Boolean syncReport = false;
/** Enable cycle report */
private Boolean cycleReport = true;
/** Cycle report period */
private Integer cycleReportPeriod = 5000;
// Getters and setters
public Boolean getSyncReport() { return syncReport; }
public void setSyncReport(Boolean syncReport) { this.syncReport = syncReport; }
public Boolean getCycleReport() { return cycleReport; }
public void setCycleReport(Boolean cycleReport) { this.cycleReport = cycleReport; }
public Integer getCycleReportPeriod() { return cycleReportPeriod; }
public void setCycleReportPeriod(Integer cycleReportPeriod) {
this.cycleReportPeriod = cycleReportPeriod;
}
}Configuration Examples:
# Enable metadata report
dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
dubbo.metadata-report.username=admin
dubbo.metadata-report.password=admin
dubbo.metadata-report.timeout=5000
dubbo.metadata-report.retry-times=3
dubbo.metadata-report.retry-period=3000
dubbo.metadata-report.cycle-report=true
dubbo.metadata-report.sync-report=false
# Metadata service configuration
dubbo.metadata-report.group=dubbo
dubbo.metadata-report.cluster=defaultYAML configuration:
dubbo:
metadata-report:
address: zookeeper://127.0.0.1:2181
username: admin
password: admin
timeout: 5000
retry-times: 3
retry-period: 3000
cycle-report: true
sync-report: false
group: dubboComplete Metadata Setup Example:
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.MetadataReportConfig;
// Configure metadata reporting
MetadataReportConfig metadataReport = new MetadataReportConfig();
metadataReport.setAddress("zookeeper://127.0.0.1:2181");
metadataReport.setGroup("dubbo");
metadataReport.setTimeout(5000);
metadataReport.setRetryTimes(3);
metadataReport.setCycleReport(true);
// Bootstrap with metadata configuration
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.metadataReport(metadataReport);
// Configure service with metadata
ServiceConfig<GreeterService> service = new ServiceConfig<>();
service.setInterface(GreeterService.class);
service.setRef(new GreeterServiceImpl());
service.setGroup("production");
service.setVersion("1.0.0");
bootstrap.service(service).start();
// Query metadata
MetadataService metadataService = bootstrap.getCache().get(MetadataService.class);
String serviceDefinition = metadataService.getServiceDefinition(
"com.example.GreeterService", "1.0.0", "production");Install with Tessl CLI
npx tessl i tessl/maven-org-apache-dubbo--dubbo