获取所有topic AdminBrokerProcessor#processRequest#getAllTopicConfig
private RemotingCommand getAllTopicConfig(ChannelHandlerContext ctx, RemotingCommand request) {
// 创建响应命令对象
final RemotingCommand response = RemotingCommand.createResponseCommand(GetAllTopicConfigResponseHeader.class);
// final GetAllTopicConfigResponseHeader responseHeader =
// (GetAllTopicConfigResponseHeader) response.readCustomHeader();
// 从本地缓存中获取所有topic信息
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;
}
从本地缓存中获取所有的topic,如果没有获取到,返回错误码ResponseCode.SYSTEM_ERROR,描述"No topic in this broker" broker中没有topic