RocketMQ源码解析之NameServer启动流程(一)

目录

1:入口

2:创建nameserverController

3:运行NamesrvController

4:注册钩子函数


1:入口

org.apache.rocketmq.namesrv.NamesrvStartup#main

org.apache.rocketmq.namesrv.NamesrvStartup#main0

 

2:创建nameserverController

org.apache.rocketmq.namesrv.NamesrvStartup#createNamesrvController

2.1:初始化NamesrvConfig参数

org.apache.rocketmq.common.namesrv.NamesrvConfig

2.2:初始化netty参数

org.apache.rocketmq.remoting.netty.NettyServerConfig

将netty之前的的默认端口8888设置成 9876

nettyServerConfig.setListenPort(9876);

2.3:构造函数创建NamesrvController

org.apache.rocketmq.namesrv.NamesrvController

2.4:注册一些配置参数

controller.getConfiguration().registerConfig(properties);

3:运行NamesrvController

org.apache.rocketmq.namesrv.NamesrvStartup#start

3.1:校验一些参数(controller)

if (null == controller) { 
    throw new IllegalArgumentException("NamesrvController is null"); 
}

 

3.2:初始化controller

boolean initResult = controller.initialize();

3.2.1:继续初始化参数

public boolean initialize() {...............
 this.kvConfigManager.load(); 
 this.remotingServer = new NettyRemotingServer(this.nettyServerConfig, 
 this.brokerHousekeepingService);
    .......
}

3.2.1:定时任务

//扫描不活跃的broker--- 用于检测和Broker之间的心跳连接 

this.scheduledExecutorService.scheduleAtFixedRate(() -> NamesrvController.this.routeInfoManager.scanNotActiveBroker(), 5, 10, TimeUnit.SECONDS);

//打印信息 
this.scheduledExecutorService.scheduleAtFixedRate(() -> NamesrvController.this.kvConfigManager.printAllPeriodically(), 1, 10, TimeUnit.MINUTES);

 

4:注册钩子函数

Runtime.getRuntime().addShutdownHook(

new ShutdownHookThread(log, (Callable) () -> { 

controller.shutdown(); 
return null; 
            }
        )
    );

你可能感兴趣的:(RocketMQ,MQ,RocketMQ,RocketMQ源码解析)