songxiaosheng commented on issue #14569:
URL: https://github.com/apache/dubbo/issues/14569#issuecomment-2308574986

   getAvailablePort is ok
   
   In this scenario, when multiple Models are created for data isolation, the 
port data cannot be isolated and only takes effect once.
   
   ```java
   public class ModelDemo {
       private static final Logger logger = 
LoggerFactory.getLogger(ModelDemo.class);
   
       public static void main(String[] args) throws InterruptedException {
         
           start(new FrameworkModel(), -1);
           logger.info("frameworkModelOne start success");
   
       
           start(new FrameworkModel(), -1);
           new CountDownLatch(1).await();
       }
   
       private static void start(FrameworkModel frameworkModel, int port) {
           //创建订单子系统应用级ApplicationModel
           ApplicationModel orderApplicationModel = 
frameworkModel.newApplication();
           //创建模块级ModuleModel
           ModuleModel moduleModel = orderApplicationModel.newModule();
           //Model的配置管理通过对应的ConfigManager进行
           ConfigManager appConfigManager = 
orderApplicationModel.getApplicationConfigManager();
           //应用配置
           ApplicationConfig application = new 
ApplicationConfig("dubbo-provider-app");
           //关闭QOS避免端口冲突
           application.setQosEnable(false);
           appConfigManager.setApplication(application);
   
           //应用层级的配置中心、元数据中心、协议默认设置
           appConfigManager.addRegistry(new 
RegistryConfig("zookeeper://127.0.0.1:2181"));
           appConfigManager.addMetadataReport(new 
MetadataReportConfig("zookeeper://127.0.0.1:2181"));
           appConfigManager.addProtocol(new 
ProtocolConfig(CommonConstants.DUBBO, port));
   
           //配置模块
           ModuleConfigManager moduleConfigManager = 
moduleModel.getConfigManager();
           moduleConfigManager.setModule(new 
ModuleConfig("dubbo-provider-app-module"));
   
           ServiceConfig<OrderService> serviceConfig = new ServiceConfig<>();
           //设置该ServiceConfig对应的ModuleModel
           serviceConfig.setScopeModel(moduleModel);
           serviceConfig.setInterface(OrderService.class);
           serviceConfig.setRef(new OrderServiceImpl());
           //为ModuleModel添加ServiceConfig
           moduleConfigManager.addConfig(serviceConfig);
           //导出服务
           serviceConfig.export();
       }
   }
   ```
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to