Java Code Examples for org.apache.rocketmq.common.namesrv.NamesrvConfig#setConfigStorePath()

The following examples show how to use org.apache.rocketmq.common.namesrv.NamesrvConfig#setConfigStorePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntegrationTestBase.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 2
Source File: IntegrationTestBase.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 3
Source File: IntegrationTestBase.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 4
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 5
Source File: IntegrationTestBase.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 6
Source File: IntegrationTestBase.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 7
Source File: IntegrationTestBase.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(9000 + random.nextInt(1000));
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed");
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 8
Source File: IntegrationTestBase.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static NamesrvController createAndStartNamesrv() {
    String baseDir = createBaseDir();
    NamesrvConfig namesrvConfig = new NamesrvConfig();
    NettyServerConfig nameServerNettyServerConfig = new NettyServerConfig();
    namesrvConfig.setKvConfigPath(baseDir + SEP + "namesrv" + SEP + "kvConfig.json");
    namesrvConfig.setConfigStorePath(baseDir + SEP + "namesrv" + SEP + "namesrv.properties");

    nameServerNettyServerConfig.setListenPort(nextPort());
    NamesrvController namesrvController = new NamesrvController(namesrvConfig, nameServerNettyServerConfig);
    try {
        Assert.assertTrue(namesrvController.initialize());
        logger.info("Name Server Start:{}", nameServerNettyServerConfig.getListenPort());
        namesrvController.start();
    } catch (Exception e) {
        logger.info("Name Server start failed", e);
        System.exit(1);
    }
    NAMESRV_CONTROLLERS.add(namesrvController);
    return namesrvController;

}
 
Example 9
Source File: NamesrvStartup.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
public static NamesrvController createNamesrvController(String[] args) throws IOException, JoranException {
//        从系统文件中查询rocketmq版本,默认4.3.0
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
//        PackageConflictDetect.detectFastjson();

//        构建命令行操作的指令 =》
        Options options = ServerUtil.buildCommandlineOptions(new Options());
//        mqnamesrv 启动namesrv命令 =》
        commandLine = ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options), new PosixParser());
        if (null == commandLine) {
//            系统非正常退出,流程结束
            System.exit(-1);
            return null;
        }

//        解析配置文件 =》
        final NamesrvConfig namesrvConfig = new NamesrvConfig();
//        =》
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
//        设置 namesrv的服务端口
        nettyServerConfig.setListenPort(9876);
//        c 指定启动的时候加载配置文件
        if (commandLine.hasOption('c')) {
//            命令行启动指定配置文件,前面用c开头
            String file = commandLine.getOptionValue('c');
            if (file != null) {
                InputStream in = new BufferedInputStream(new FileInputStream(file));
                properties = new Properties();
                properties.load(in);
                MixAll.properties2Object(properties, namesrvConfig);
                MixAll.properties2Object(properties, nettyServerConfig);

//                设置命令行启动namesrv指定的配置文件路径
                namesrvConfig.setConfigStorePath(file);

                System.out.printf("load config properties file OK, %s%n", file);
                in.close();
            }
        }

//        打印namesrv的配置信息,命令行上面加p
        if (commandLine.hasOption('p')) {
            MixAll.printObjectProperties(null, namesrvConfig);
            MixAll.printObjectProperties(null, nettyServerConfig);
//            正常程序退出
            System.exit(0);
        }

//        把命令行属性解析成properties
        MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), namesrvConfig);

//        解析 ROCKETMQ_HOME 环境变量
        if (null == namesrvConfig.getRocketmqHome()) {
            System.out.printf("Please set the %s variable in your environment to match the location of the RocketMQ installation%n", MixAll.ROCKETMQ_HOME_ENV);
//            系统非正常退出
            System.exit(-2);
        }

        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        lc.reset();
//        logback日志文件路径
        configurator.doConfigure(namesrvConfig.getRocketmqHome() + "/conf/logback_namesrv.xml");

        log = InternalLoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME);

        MixAll.printObjectProperties(log, namesrvConfig);
        MixAll.printObjectProperties(log, nettyServerConfig);

//        创建namesrv控制器 =》
        final NamesrvController controller = new NamesrvController(namesrvConfig, nettyServerConfig);

        // remember all configs to prevent discard 把配置文件配置值的属性值注册到namesrv控制器
        controller.getConfiguration().registerConfig(properties);

        return controller;
    }
 
Example 10
Source File: NamesrvStartup.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
public static NamesrvController createNamesrvController(String[] args) throws IOException, JoranException {
        System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
        //PackageConflictDetect.detectFastjson();

        Options options = ServerUtil.buildCommandlineOptions(new Options());
        commandLine = ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options), new PosixParser());
        if (null == commandLine) {
            System.exit(-1);
            return null;
        }

        final NamesrvConfig namesrvConfig = new NamesrvConfig();
        final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(9876);
        if (commandLine.hasOption('c')) {
            String file = commandLine.getOptionValue('c');
            if (file != null) {
                InputStream in = new BufferedInputStream(new FileInputStream(file));
                properties = new Properties();
                properties.load(in);
                MixAll.properties2Object(properties, namesrvConfig);
                MixAll.properties2Object(properties, nettyServerConfig);

                namesrvConfig.setConfigStorePath(file);

                System.out.printf("load config properties file OK, %s%n", file);
                in.close();
            }
        }

        if (commandLine.hasOption('p')) {
            InternalLogger console = InternalLoggerFactory.getLogger(LoggerName.NAMESRV_CONSOLE_NAME);
            MixAll.printObjectProperties(console, namesrvConfig);
            MixAll.printObjectProperties(console, nettyServerConfig);
            System.exit(0);
        }

        MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), namesrvConfig);

        if (null == namesrvConfig.getRocketmqHome()) {
            System.out.printf("Please set the %s variable in your environment to match the location of the RocketMQ installation%n", MixAll.ROCKETMQ_HOME_ENV);
            System.exit(-2);
        }

        //把下面这些日志都注掉,影响打日志查看
//        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
//        JoranConfigurator configurator = new JoranConfigurator();
//        configurator.setContext(lc);
//        lc.reset();
//       configurator.doConfigure(namesrvConfig.getRocketmqHome() + "/conf/logback_namesrv.xml");

        log = InternalLoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME);

        MixAll.printObjectProperties(log, namesrvConfig);
        MixAll.printObjectProperties(log, nettyServerConfig);

        final NamesrvController controller = new NamesrvController(namesrvConfig, nettyServerConfig);

        // remember all configs to prevent discard
        controller.getConfiguration().registerConfig(properties);

        return controller;
    }
 
Example 11
Source File: NamesrvStartup.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public static NamesrvController createNamesrvController(String[] args) throws IOException, JoranException {
    System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION));
    //PackageConflictDetect.detectFastjson();

    Options options = ServerUtil.buildCommandlineOptions(new Options());
    commandLine = ServerUtil.parseCmdLine("mqnamesrv", args, buildCommandlineOptions(options), new PosixParser());
    if (null == commandLine) {
        System.exit(-1);
        return null;
    }

    final NamesrvConfig namesrvConfig = new NamesrvConfig();
    final NettyServerConfig nettyServerConfig = new NettyServerConfig();
    nettyServerConfig.setListenPort(9876);
    if (commandLine.hasOption('c')) {
        String file = commandLine.getOptionValue('c');
        if (file != null) {
            InputStream in = new BufferedInputStream(new FileInputStream(file));
            properties = new Properties();
            properties.load(in);
            MixAll.properties2Object(properties, namesrvConfig);
            MixAll.properties2Object(properties, nettyServerConfig);

            namesrvConfig.setConfigStorePath(file);

            System.out.printf("load config properties file OK, %s%n", file);
            in.close();
        }
    }

    if (commandLine.hasOption('p')) {
        InternalLogger console = InternalLoggerFactory.getLogger(LoggerName.NAMESRV_CONSOLE_NAME);
        MixAll.printObjectProperties(console, namesrvConfig);
        MixAll.printObjectProperties(console, nettyServerConfig);
        System.exit(0);
    }

    MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), namesrvConfig);

    if (null == namesrvConfig.getRocketmqHome()) {
        System.out.printf("Please set the %s variable in your environment to match the location of the RocketMQ installation%n", MixAll.ROCKETMQ_HOME_ENV);
        System.exit(-2);
    }

    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(namesrvConfig.getRocketmqHome() + "/conf/logback_namesrv.xml");

    log = InternalLoggerFactory.getLogger(LoggerName.NAMESRV_LOGGER_NAME);

    MixAll.printObjectProperties(log, namesrvConfig);
    MixAll.printObjectProperties(log, nettyServerConfig);

    final NamesrvController controller = new NamesrvController(namesrvConfig, nettyServerConfig);

    // remember all configs to prevent discard
    controller.getConfiguration().registerConfig(properties);

    return controller;
}