You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AlbumenJ (via GitHub)" <gi...@apache.org> on 2023/04/04 09:24:06 UTC

[GitHub] [dubbo] AlbumenJ commented on a diff in pull request #11981: Update demos (#11970)

AlbumenJ commented on code in PR #11981:
URL: https://github.com/apache/dubbo/pull/11981#discussion_r1156974561


##########
dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java:
##########
@@ -47,23 +60,47 @@ private static void startWithBootstrap() {
 
         DubboBootstrap bootstrap = DubboBootstrap.getInstance();
         bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider"))
-            .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
+            .registry(new RegistryConfig(REGISTRY_URL))
             .protocol(new ProtocolConfig(CommonConstants.DUBBO, -1))
             .service(service)
             .start()
             .await();
     }
 
     private static void startWithExport() throws InterruptedException {
-        ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
-        service.setInterface(DemoService.class);
-        service.setRef(new DemoServiceImpl());
-        service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
-        service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
-        service.setMetadataReportConfig(new MetadataReportConfig("zookeeper://127.0.0.1:2181"));
-        service.export();
+        FrameworkModel frameworkModel = new FrameworkModel();
+        ApplicationModel applicationModel = frameworkModel.newApplication();
+        ModuleModel moduleModel = applicationModel.newModule();
+
+        RegistryConfig registryConfig = new RegistryConfig(REGISTRY_URL);
+        MetadataReportConfig metadataReportConfig = new MetadataReportConfig(METADATA_REPORT_URL);
+        ProtocolConfig protocolConfig = new ProtocolConfig(CommonConstants.DUBBO, -1);
+
+        final String registryId = "registry-1";
+        final String metadataId = "metadata-1";
+        registryConfig.setId(registryId);
+        metadataReportConfig.setId(metadataId);
+
+        ConfigManager appConfigManager = applicationModel.getApplicationConfigManager();
+        appConfigManager.setApplication(new ApplicationConfig("dubbo-demo-api-provider-app-1"));
+        appConfigManager.addRegistry(registryConfig);
+        appConfigManager.addMetadataReport(metadataReportConfig);
+        appConfigManager.addProtocol(protocolConfig);
+
+        ModuleConfigManager moduleConfigManager = moduleModel.getConfigManager();
+        moduleConfigManager.setModule(new ModuleConfig("dubbo-demo-api-provider-app-1-module-1"));
+
+        ServiceConfig<DemoService> serviceConfig = new ServiceConfig<>();
+        serviceConfig.setScopeModel(moduleModel);
+        serviceConfig.setProtocol(protocolConfig);
+        serviceConfig.setInterface(DemoService.class);
+        serviceConfig.setRef(new DemoServiceImpl());
+
+        moduleConfigManager.addConfig(serviceConfig);
+
+        serviceConfig.export();
 
-        System.out.println("dubbo service started");
         new CountDownLatch(1).await();
     }
+

Review Comment:
   Leave bootstrap here is enough



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org