命令行主类:org.apache.rocketmq.tools.command.MQAdminStartup
客户端创建 topic
程序参数:
updateTopic -n localhost:9876 -c DefaultCluster -t topic-zhang
org.apache.rocketmq.tools.command.topic.UpdateTopicSubCommand#execute
创建 topic 步骤:
1. 从 nameserver 获取当前集群的 master broker
2. 向 master 发送请求,创建 topic
3. broker 利用 registerBroker 同步新建的 topic 到 nameserver
broker 发送请求:org.apache.rocketmq.broker.BrokerController#registerIncrementBrokerData
客户端删除 topic
程序参数:
deleteTopic -n localhost:9876 -c DefaultCluster -t topic-zhang
org.apache.rocketmq.tools.command.topic.DeleteTopicSubCommand#deleteTopic
删除 topic 步骤:
1. client 从 nameserver 获取 broker 列表
2. 向 broker 发送请求,删除 broker 中的 topic
broker 删除 topic
org.apache.rocketmq.broker.topic.TopicConfigManager#deleteTopicConfig
3. 向 nameserver 发送请求, 删除 nameserver 中的 topic
同时,broker 和 nameserver 之间有定时的 registerBroker,10s 一次:
org.apache.rocketmq.broker.BrokerController#start
this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { BrokerController.this.registerBrokerAll(true, false, brokerConfig.isForceRegister()); } catch (Throwable e) { log.error("registerBrokerAll Exception", e); } } }, 1000 * 10, Math.max(10000, Math.min(brokerConfig.getRegisterNameServerPeriod(), 60000)), TimeUnit.MILLISECONDS);
org.apache.rocketmq.namesrv.NamesrvController#initialize
this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { NamesrvController.this.routeInfoManager.scanNotActiveBroker(); } }, 5, 10, TimeUnit.SECONDS);