apache/dubbo

Support set fixed rmi service port

Open

#6,629 创建于 2020年8月20日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)Java (26,453 fork)batch import
help wantedtype/proposal

仓库指标

Star
 (41,524 star)
PR 合并指标
 (平均合并 7天 14小时) (30 天内合并 20 个 PR)

描述

Rmi protocal will choose a random port as the service port. Sometimes we need to use a fixed port to ensure it is accessable from other service instance. Could add a parameter to support setting this port?

Here is my current code to set the service port.

org.apache.dubbo.rpc.protocol.rmi.RmiProtocol

  @Override
  protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    RmiServiceExporter rmiServiceExporter = createExporter(impl, type, url, false);
    RmiServiceExporter genericServiceExporter =
        createExporter(impl, GenericService.class, url, true);

    // Here is the code to set the fixed service port.
    String servicePort = System.getProperty("dubbo.protocal.rmi.serviceport");
    if (servicePort != null && !servicePort.isEmpty()) {
      rmiServiceExporter.setServicePort(Integer.valueOf(servicePort));
    }

    return new Runnable() {
      @Override
      public void run() {
        try {
          rmiServiceExporter.destroy();
          genericServiceExporter.destroy();
        } catch (Throwable e) {
          logger.warn(e.getMessage(), e);
        }
      }
    };
  }

贡献者指南