说在前面
今天解析管理请求处理之GET_ALL_TOPIC_CONFIG获取所有topic配置信息,更多源码解析请关注“天河聊架构”微信公众号
源码解析
进入这个方法org.apache.rocketmq.broker.processor.AdminBrokerProcessor#getAllTopicConfig
private RemotingCommand getAllTopicConfig(ChannelHandlerContext ctx, RemotingCommand request) {
final RemotingCommand response = RemotingCommand.createResponseCommand(GetAllTopicConfigResponseHeader.class);
// final GetAllTopicConfigResponseHeader responseHeader =
// (GetAllTopicConfigResponseHeader) response.readCustomHeader();
// 从本地缓存中获取信息
String content = this.brokerController.getTopicConfigManager().encode();
if (content != null && content.length() > 0) {
try {
response.setBody(content.getBytes(MixAll.DEFAULT_CHARSET));
} catch (UnsupportedEncodingException e) {
log.error("", e);
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("UnsupportedEncodingException " + e);
return response;
}
} else {
log.error("No topic in this broker, client: {}", ctx.channel().remoteAddress());
response.setCode(ResponseCode.SYSTEM_ERROR);
response.setRemark("No topic in this broker");
return response;
}
response.setCode(ResponseCode.SUCCESS);
response.setRemark(null);
return response;
}
进入这个方法org.apache.rocketmq.broker.topic.TopicConfigManager#encode(boolean) 对topicConfig信息进行json编码
public String encode(final boolean prettyFormat) {
TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
topicConfigSerializeWrapper.setTopicConfigTable(this.topicConfigTable);
topicConfigSerializeWrapper.setDataVersion(this.dataVersion);
return topicConfigSerializeWrapper.toJson(prettyFormat);
}
往上返回到这个方法org.apache.rocketmq.broker.processor.AdminBrokerProcessor#getAllTopicConfig 解析结束。
说在最后
本次解析仅代表个人观点,仅供参考。
加入技术微信群
钉钉技术群