Metadata Center Extension

Metadata Center Extension

Design Purpose

Please refer to the Metadata Center Manual

Extension Interfaces

  • org.apache.dubbo.metadata.store.MetadataReportFactory
  • org.apache.dubbo.metadata.store.MetadataReport

Known Extensions

Implementation Principles

SPI Definition

Reference: org.apache.dubbo.metadata.store.MetadataReportFactory, org.apache.dubbo.metadata.store.MetadataReport

  1. @SPI("redis")
  2. public interface MetadataReportFactory {
  3. @Adaptive({"protocol"})
  4. MetadataReport getMetadataReport(URL url);
  5. }

Custom Metadata Storage

The following example describes the Redis storage.

Create a new project that needs to support the following modifications:

Extend AbstractMetadataReport

  1. public class RedisMetadataReport extends AbstractMetadataReport {
  2. private final static Logger logger = LoggerFactory.getLogger(RedisMetadataReport.class);
  3. final JedisPool pool;
  4. public RedisMetadataReport(URL url) {
  5. super(url);
  6. pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort());
  7. }
  8. @Override
  9. protected void doStoreProviderMetadata(ProviderMetadataIdentifier providerMetadataIdentifier, String serviceDefinitions) {
  10. this.storeMetadata(providerMetadataIdentifier, serviceDefinitions);
  11. }
  12. @Override
  13. protected void doStoreConsumerMetadata(ConsumerMetadataIdentifier consumerMetadataIdentifier, String value) {
  14. this.storeMetadata(consumerMetadataIdentifier, value);
  15. }
  16. private void storeMetadata(MetadataIdentifier metadataIdentifier, String v) {
  17. try (Jedis jedis = pool.getResource()) {
  18. jedis.set(metadataIdentifier.getIdentifierKey() + META_DATA_SOTRE_TAG, v);
  19. } catch (Throwable e) {
  20. logger.error("Failed to put " + metadataIdentifier + " to redis " + v + ", cause: " + e.getMessage(), e);
  21. throw new RpcException("Failed to put " + metadataIdentifier + " to redis " + v + ", cause: " + e.getMessage(), e);
  22. }
  23. }
  24. }

Extend AbstractMetadataReportFactory

  1. public class RedisMetadataReportFactory extends AbstractMetadataReportFactory {
  2. @Override
  3. public MetadataReport createMetadataReport(URL url) {
  4. return new RedisMetadataReport(url);
  5. }
  6. }

Add MetadataReportFactory

META-INF/dubbo/internal/org.apache.dubbo.metadata.store.MetadataReportFactory

  1. redis=org.apache.dubbo.metadata.store.redis.RedisMetadataReportFactory

Just package the above modifications and the project into a jar file, then configure the metadata center’s URL: redis://10.20.153.10:6379.

Thus, a custom metadata storage can now run.

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)