com.alibaba.rocketmq.common.namesrv.RegisterBrokerResult Java Examples

The following examples show how to use com.alibaba.rocketmq.common.namesrv.RegisterBrokerResult. 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: DefaultRequestProcessor.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public RemotingCommand registerBrokerWithFilterServer(ChannelHandlerContext ctx, RemotingCommand request)
        throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class);
    final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader();
    final RegisterBrokerRequestHeader requestHeader =
            (RegisterBrokerRequestHeader) request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class);

    RegisterBrokerBody registerBrokerBody = new RegisterBrokerBody();

    if (request.getBody() != null) {
        registerBrokerBody = RegisterBrokerBody.decode(request.getBody(), RegisterBrokerBody.class);
    }
    else {
        registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setCounter(new AtomicLong(0));
        registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setTimestatmp(0);
    }

    RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker(//
        requestHeader.getClusterName(), // 1
        requestHeader.getBrokerAddr(), // 2
        requestHeader.getBrokerName(), // 3
        requestHeader.getBrokerId(), // 4
        requestHeader.getHaServerAddr(),// 5
        registerBrokerBody.getTopicConfigSerializeWrapper(), // 6
        registerBrokerBody.getFilterServerList(),//
        ctx.channel()// 7
        );

    responseHeader.setHaServerAddr(result.getHaServerAddr());
    responseHeader.setMasterAddr(result.getMasterAddr());

    byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG);
    response.setBody(jsonValue);

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #2
Source File: BrokerOuterAPI.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
/**
     * 有topic配置信息发生变化的时候 ,推送到nameserver .
     * @param clusterName broker归属的集群
     * @param brokerAddr broker的地址。
     * @param brokerName broker名称,理解为一主多备组合而成的broker单元。
     * @param brokerId broker编号, 大于0则为slave  ,为0则为master .
     * @param haServerAddr 用于主备复制的ha 地址。
     * @param topicConfigWrapper topic配置的包装器。
     * @param filterServerList 过滤服务器列表(一个broker可以有多个过滤服务器 ?)
     * @param oneway 单向调用。
     * @return
     */
//把broker维护的topic配置推送给namserver, 同时把broker注册到Nameserver 或者BrokerController.start 每隔30s定时时间到,都会发送该报文,除了通知为,也是broker与nameserver的保活报文
    public RegisterBrokerResult registerBrokerAll(//
            final String clusterName,// 1
            final String brokerAddr,// 2
            final String brokerName,// 3
            final long brokerId,// 4
            final String haServerAddr,// 5
            final TopicConfigSerializeWrapper topicConfigWrapper,// 6
            final List<String> filterServerList,// 7
            final boolean oneway// 8
    ) {
        RegisterBrokerResult registerBrokerResult = null;

        List<String> nameServerAddressList = this.remotingClient.getNameServerAddressList();
        if (nameServerAddressList != null) {
            for (String namesrvAddr : nameServerAddressList) { //把信息写到多个nameserver如何保证数据的一致性。
                try {
                    RegisterBrokerResult result =
                            this.registerBroker(namesrvAddr, clusterName, brokerAddr, brokerName, brokerId,
                                haServerAddr, topicConfigWrapper, filterServerList, oneway);
                    if (result != null) {
                        registerBrokerResult = result;
                    }

                    log.info("register broker to name server {} OK", namesrvAddr);
                }
                catch (Exception e) {
                    log.warn("registerBroker Exception, " + namesrvAddr, e);
                }
            }
        }

        return registerBrokerResult;
    }
 
Example #3
Source File: DefaultRequestProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public RemotingCommand registerBrokerWithFilterServer(ChannelHandlerContext ctx, RemotingCommand request)
        throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class);
    final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader();
    final RegisterBrokerRequestHeader requestHeader =
            (RegisterBrokerRequestHeader) request.decodeCommandCustomHeader(RegisterBrokerRequestHeader.class);

    RegisterBrokerBody registerBrokerBody = new RegisterBrokerBody();

    if (request.getBody() != null) {
        registerBrokerBody = RegisterBrokerBody.decode(request.getBody(), RegisterBrokerBody.class);
    } else {
        registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setCounter(new AtomicLong(0));
        registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setTimestatmp(0);
    }

    RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker(//
            requestHeader.getClusterName(), // 1
            requestHeader.getBrokerAddr(), // 2
            requestHeader.getBrokerName(), // 3
            requestHeader.getBrokerId(), // 4
            requestHeader.getHaServerAddr(),// 5
            registerBrokerBody.getTopicConfigSerializeWrapper(), // 6
            registerBrokerBody.getFilterServerList(),//
            ctx.channel()// 7
    );

    responseHeader.setHaServerAddr(result.getHaServerAddr());
    responseHeader.setMasterAddr(result.getMasterAddr());


    byte[] jsonValue = this.namesrvController.getKvConfigManager().getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG);
    response.setBody(jsonValue);

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #4
Source File: BrokerController.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway) {
    TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

    if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
            || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
        ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<String, TopicConfig>();
        for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
            TopicConfig tmp =
                    new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                            this.brokerConfig.getBrokerPermission());
            topicConfigTable.put(topicConfig.getTopicName(), tmp);
        }
        topicConfigWrapper.setTopicConfigTable(topicConfigTable);
    }

    RegisterBrokerResult registerBrokerResult = this.brokerOuterAPI.registerBrokerAll(//
            this.brokerConfig.getBrokerClusterName(), //
            this.getBrokerAddr(), //
            this.brokerConfig.getBrokerName(), //
            this.brokerConfig.getBrokerId(), //
            this.getHAServerAddr(), //
            topicConfigWrapper,//
            this.filterServerManager.buildNewFilterServerList(),//
            oneway,//
            this.brokerConfig.getRegisterBrokerTimeoutMills());

    if (registerBrokerResult != null) {
        if (this.updateMasterHAServerAddrPeriodically && registerBrokerResult.getHaServerAddr() != null) {
            this.messageStore.updateHaMasterAddress(registerBrokerResult.getHaServerAddr());
        }

        this.slaveSynchronize.setMasterAddr(registerBrokerResult.getMasterAddr());

        if (checkOrderConfig) {
            this.getTopicConfigManager().updateOrderTopicConfig(registerBrokerResult.getKvTable());
        }
    }
}
 
Example #5
Source File: BrokerOuterAPI.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public RegisterBrokerResult registerBrokerAll(//
                                              final String clusterName, // 1
                                              final String brokerAddr, // 2
                                              final String brokerName, // 3
                                              final long brokerId, // 4
                                              final String haServerAddr, // 5
                                              final TopicConfigSerializeWrapper topicConfigWrapper, // 6
                                              final List<String> filterServerList, // 7
                                              final boolean oneway,// 8
                                              final int timeoutMills// 9
) {
    RegisterBrokerResult registerBrokerResult = null;

    List<String> nameServerAddressList = this.remotingClient.getNameServerAddressList();
    if (nameServerAddressList != null) {
        for (String namesrvAddr : nameServerAddressList) {
            try {
                RegisterBrokerResult result = this.registerBroker(namesrvAddr, clusterName, brokerAddr, brokerName, brokerId,
                        haServerAddr, topicConfigWrapper, filterServerList, oneway, timeoutMills);
                if (result != null) {
                    registerBrokerResult = result;
                }

                log.info("register broker to name server {} OK", namesrvAddr);
            } catch (Exception e) {
                log.warn("registerBroker Exception, " + namesrvAddr, e);
            }
        }
    }

    return registerBrokerResult;
}
 
Example #6
Source File: BrokerController.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway) {
    TopicConfigSerializeWrapper topicConfigWrapper =
            this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

    if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
            || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
        ConcurrentHashMap<String, TopicConfig> topicConfigTable =
                new ConcurrentHashMap<String, TopicConfig>(topicConfigWrapper.getTopicConfigTable());
        for (TopicConfig topicConfig : topicConfigTable.values()) {
            topicConfig.setPerm(this.getBrokerConfig().getBrokerPermission());
        }
        topicConfigWrapper.setTopicConfigTable(topicConfigTable);
    }

    RegisterBrokerResult registerBrokerResult = this.brokerOuterAPI.registerBrokerAll(//
        this.brokerConfig.getBrokerClusterName(), //
        this.getBrokerAddr(), //
        this.brokerConfig.getBrokerName(), //
        this.brokerConfig.getBrokerId(), //
        this.getHAServerAddr(), //
        topicConfigWrapper, //
        this.filterServerManager.buildNewFilterServerList(), //
        oneway);

    if (registerBrokerResult != null) {
        if (this.updateMasterHAServerAddrPeriodically && registerBrokerResult.getHaServerAddr() != null) {
            this.messageStore.updateHaMasterAddress(registerBrokerResult.getHaServerAddr());
        }

        this.slaveSynchronize.setMasterAddr(registerBrokerResult.getMasterAddr());

        if (checkOrderConfig) {
            this.getTopicConfigManager().updateOrderTopicConfig(registerBrokerResult.getKvTable());
        }
    }
}
 
Example #7
Source File: BrokerOuterAPI.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public RegisterBrokerResult registerBrokerAll(//
        final String clusterName, // 1
        final String brokerAddr, // 2
        final String brokerName, // 3
        final long brokerId, // 4
        final String haServerAddr, // 5
        final TopicConfigSerializeWrapper topicConfigWrapper, // 6
        final List<String> filterServerList, // 7
        final boolean oneway// 8
) {
    RegisterBrokerResult registerBrokerResult = null;

    List<String> nameServerAddressList = this.remotingClient.getNameServerAddressList();
    if (nameServerAddressList != null) {
        for (String namesrvAddr : nameServerAddressList) {
            try {
                RegisterBrokerResult result = this.registerBroker(namesrvAddr, clusterName, brokerAddr,
                    brokerName, brokerId, haServerAddr, topicConfigWrapper, filterServerList, oneway);
                if (result != null) {
                    registerBrokerResult = result;
                }

                log.info("register broker to name server {} OK", namesrvAddr);
            }
            catch (Exception e) {
                log.warn("registerBroker Exception, " + namesrvAddr, e);
            }
        }
    }

    return registerBrokerResult;
}
 
Example #8
Source File: BrokerController.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway) {
        TopicConfigSerializeWrapper topicConfigWrapper = this.getTopicConfigManager().buildTopicConfigSerializeWrapper();

        /**
         * broker本身不可读或者不可写,则用 broker 本身的权限配置覆盖topic的读写权限。
         * 或者简单说 ,broker的读写权限比topic的读写权限具有更高的优先级。
         *
         */
        if (!PermName.isWriteable(this.getBrokerConfig().getBrokerPermission())
                || !PermName.isReadable(this.getBrokerConfig().getBrokerPermission())) {
            ConcurrentHashMap<String, TopicConfig> topicConfigTable = new ConcurrentHashMap<String, TopicConfig>();
            //遍历该broker下面的所有topic信息
            for (TopicConfig topicConfig : topicConfigWrapper.getTopicConfigTable().values()) {
                TopicConfig tmp =
                        new TopicConfig(topicConfig.getTopicName(), topicConfig.getReadQueueNums(), topicConfig.getWriteQueueNums(),
                            this.brokerConfig.getBrokerPermission()); //把所有的broker下面的topic信息的读写权限修改为何broker一致
                topicConfigTable.put(topicConfig.getTopicName(), tmp);
            }
            topicConfigWrapper.setTopicConfigTable(topicConfigTable); //把修改权限后的topic信息topicConfigTable重新赋值给topicConfigWrapper
        }

//把broker维护的topic配置推送给namserver, 同时把broker注册到Nameserver 或者BrokerController.start 每隔30s定时时间到,都会发送该报文,除了通知为,也是broker与nameserver的保活报文
        RegisterBrokerResult registerBrokerResult = this.brokerOuterAPI.registerBrokerAll(//
            this.brokerConfig.getBrokerClusterName(), //
            this.getBrokerAddr(), //
            this.brokerConfig.getBrokerName(), //
            this.brokerConfig.getBrokerId(), //
            this.getHAServerAddr(), //
            topicConfigWrapper,//
            this.filterServerManager.buildNewFilterServerList(),//
            oneway);

        if (registerBrokerResult != null) {
            //registerBrokerResult.getHaServerAddr() != null 标识当前broker是slave,则需要把ha server的地址更新掉。
            //所谓ha是 master broker用于主从数据同步的IP + 端口。
            if (this.updateMasterHAServerAddrPeriodically && registerBrokerResult.getHaServerAddr() != null) {
                this.messageStore.updateHaMasterAddress(registerBrokerResult.getHaServerAddr());
            }

            this.slaveSynchronize.setMasterAddr(registerBrokerResult.getMasterAddr());

            if (checkOrderConfig) {
                this.getTopicConfigManager().updateOrderTopicConfig(registerBrokerResult.getKvTable());
            }
        }
    }
 
Example #9
Source File: BrokerOuterAPI.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 把broker注册到nameserver.  同时把broker管理的topic配置信息提交给nameserver进行维护。
 * @param namesrvAddr
 * @param clusterName
 * @param brokerAddr
 * @param brokerName
 * @param brokerId
 * @param haServerAddr
 * @param topicConfigWrapper
 * @param filterServerList
 * @param oneway
 * @return
 * @throws RemotingCommandException
 * @throws MQBrokerException
 * @throws RemotingConnectException
 * @throws RemotingSendRequestException
 * @throws RemotingTimeoutException
 * @throws InterruptedException
 */
private RegisterBrokerResult registerBroker(//
        final String namesrvAddr,//
        final String clusterName,// 1
        final String brokerAddr,// 2
        final String brokerName,// 3
        final long brokerId,// 4
        final String haServerAddr,// 5
        final TopicConfigSerializeWrapper topicConfigWrapper, // 6
        final List<String> filterServerList,// 7
        final boolean oneway// 8
) throws RemotingCommandException, MQBrokerException, RemotingConnectException,
        RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    RegisterBrokerRequestHeader requestHeader = new RegisterBrokerRequestHeader();
    requestHeader.setBrokerAddr(brokerAddr);
    requestHeader.setBrokerId(brokerId);
    requestHeader.setBrokerName(brokerName);
    requestHeader.setClusterName(clusterName);
    requestHeader.setHaServerAddr(haServerAddr);
    RemotingCommand request =
            RemotingCommand.createRequestCommand(RequestCode.REGISTER_BROKER, requestHeader);

    RegisterBrokerBody requestBody = new RegisterBrokerBody();
    requestBody.setTopicConfigSerializeWrapper(topicConfigWrapper);
    requestBody.setFilterServerList(filterServerList);
    request.setBody(requestBody.encode());

    if (oneway) {
        try {
            this.remotingClient.invokeOneway(namesrvAddr, request, 3000);
        }
        catch (RemotingTooMuchRequestException e) {
        }
        return null;
    }

    RemotingCommand response = this.remotingClient.invokeSync(namesrvAddr, request, 3000);
    assert response != null;
    switch (response.getCode()) {
    case ResponseCode.SUCCESS: {
        RegisterBrokerResponseHeader responseHeader =
                (RegisterBrokerResponseHeader) response
                    .decodeCommandCustomHeader(RegisterBrokerResponseHeader.class);
        RegisterBrokerResult result = new RegisterBrokerResult();
        result.setMasterAddr(responseHeader.getMasterAddr());
        result.setHaServerAddr(responseHeader.getHaServerAddr());
        result.setHaServerAddr(responseHeader.getHaServerAddr());
        if (response.getBody() != null) {
            result.setKvTable(KVTable.decode(response.getBody(), KVTable.class));
        }
        return result;
    }
    default:
        break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #10
Source File: BrokerOuterAPI.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private RegisterBrokerResult registerBroker(//
                                            final String namesrvAddr, //
                                            final String clusterName, // 1
                                            final String brokerAddr, // 2
                                            final String brokerName, // 3
                                            final long brokerId, // 4
                                            final String haServerAddr, // 5
                                            final TopicConfigSerializeWrapper topicConfigWrapper, // 6
                                            final List<String> filterServerList, // 7
                                            final boolean oneway,// 8
                                            final int timeoutMills// 9
) throws RemotingCommandException, MQBrokerException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException,
        InterruptedException {
    RegisterBrokerRequestHeader requestHeader = new RegisterBrokerRequestHeader();
    requestHeader.setBrokerAddr(brokerAddr);
    requestHeader.setBrokerId(brokerId);
    requestHeader.setBrokerName(brokerName);
    requestHeader.setClusterName(clusterName);
    requestHeader.setHaServerAddr(haServerAddr);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.REGISTER_BROKER, requestHeader);

    RegisterBrokerBody requestBody = new RegisterBrokerBody();
    requestBody.setTopicConfigSerializeWrapper(topicConfigWrapper);
    requestBody.setFilterServerList(filterServerList);
    request.setBody(requestBody.encode());

    if (oneway) {
        try {
            this.remotingClient.invokeOneway(namesrvAddr, request, timeoutMills);
        } catch (RemotingTooMuchRequestException e) {
        }
        return null;
    }

    RemotingCommand response = this.remotingClient.invokeSync(namesrvAddr, request, timeoutMills);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            RegisterBrokerResponseHeader responseHeader =
                    (RegisterBrokerResponseHeader) response.decodeCommandCustomHeader(RegisterBrokerResponseHeader.class);
            RegisterBrokerResult result = new RegisterBrokerResult();
            result.setMasterAddr(responseHeader.getMasterAddr());
            result.setHaServerAddr(responseHeader.getHaServerAddr());
            result.setHaServerAddr(responseHeader.getHaServerAddr());
            if (response.getBody() != null) {
                result.setKvTable(KVTable.decode(response.getBody(), KVTable.class));
            }
            return result;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #11
Source File: DefaultRequestProcessor.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public RemotingCommand registerBrokerWithFilterServer(ChannelHandlerContext ctx, RemotingCommand request)
        throws RemotingCommandException {
    final RemotingCommand response =
            RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class);
    final RegisterBrokerResponseHeader responseHeader =
            (RegisterBrokerResponseHeader) response.readCustomHeader();
    final RegisterBrokerRequestHeader requestHeader = (RegisterBrokerRequestHeader) request
        .decodeCommandCustomHeader(RegisterBrokerRequestHeader.class);

    RegisterBrokerBody registerBrokerBody = new RegisterBrokerBody();

    if (request.getBody() != null) {
        registerBrokerBody = RegisterBrokerBody.decode(request.getBody(), RegisterBrokerBody.class);
    }
    else {
        registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion()
            .setCounter(new AtomicLong(0));
        registerBrokerBody.getTopicConfigSerializeWrapper().getDataVersion().setTimestatmp(0);
    }

    RegisterBrokerResult result = this.namesrvController.getRouteInfoManager().registerBroker(//
        requestHeader.getClusterName(), // 1
        requestHeader.getBrokerAddr(), // 2
        requestHeader.getBrokerName(), // 3
        requestHeader.getBrokerId(), // 4
        requestHeader.getHaServerAddr(), // 5
        registerBrokerBody.getTopicConfigSerializeWrapper(), // 6
        registerBrokerBody.getFilterServerList(), //
        ctx.channel()// 7
    );

    responseHeader.setHaServerAddr(result.getHaServerAddr());
    responseHeader.setMasterAddr(result.getMasterAddr());

    // 获取顺序消息 topic 列表
    byte[] jsonValue = this.namesrvController.getKvConfigManager()
        .getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG);
    response.setBody(jsonValue);

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #12
Source File: BrokerOuterAPI.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
/**
 * 向nameserver注册broker
 * 
 * @param namesrvAddr
 *            nameserver IP地址端口
 * @param clusterName
 *            集群名称
 * @param brokerAddr
 *            broker IP地址端口
 * @param brokerName
 *            broker 名
 * @param brokerId
 * @param haServerAddr
 * @param topicConfigWrapper
 * @param filterServerList
 * @param oneway
 * @return
 * @throws RemotingCommandException
 * @throws MQBrokerException
 * @throws RemotingConnectException
 * @throws RemotingSendRequestException
 * @throws RemotingTimeoutException
 * @throws InterruptedException
 */
private RegisterBrokerResult registerBroker(//
        final String namesrvAddr, //
        final String clusterName, // 1
        final String brokerAddr, // 2
        final String brokerName, // 3
        final long brokerId, // 4
        final String haServerAddr, // 5
        final TopicConfigSerializeWrapper topicConfigWrapper, // 6
        final List<String> filterServerList, // 7
        final boolean oneway// 8
) throws RemotingCommandException, MQBrokerException, RemotingConnectException,
        RemotingSendRequestException, RemotingTimeoutException, InterruptedException {

    RegisterBrokerRequestHeader requestHeader = new RegisterBrokerRequestHeader();
    requestHeader.setBrokerAddr(brokerAddr);
    requestHeader.setBrokerId(brokerId);
    requestHeader.setBrokerName(brokerName);
    requestHeader.setClusterName(clusterName);
    requestHeader.setHaServerAddr(haServerAddr);
    RemotingCommand request =
            RemotingCommand.createRequestCommand(RequestCode.REGISTER_BROKER, requestHeader);

    RegisterBrokerBody requestBody = new RegisterBrokerBody();
    requestBody.setTopicConfigSerializeWrapper(topicConfigWrapper);
    requestBody.setFilterServerList(filterServerList);
    request.setBody(requestBody.encode());

    if (oneway) {
        try {
            // 建立和nameserver的连接
            this.remotingClient.invokeOneway(namesrvAddr, request, 3000);
        }
        catch (RemotingTooMuchRequestException e) {
        }
        return null;
    }

    RemotingCommand response = this.remotingClient.invokeSync(namesrvAddr, request, 3000);
    assert response != null;
    switch (response.getCode()) {
    case ResponseCode.SUCCESS: {
        RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response
            .decodeCommandCustomHeader(RegisterBrokerResponseHeader.class);
        RegisterBrokerResult result = new RegisterBrokerResult();
        result.setMasterAddr(responseHeader.getMasterAddr());
        result.setHaServerAddr(responseHeader.getHaServerAddr());
        result.setHaServerAddr(responseHeader.getHaServerAddr());
        if (response.getBody() != null) {
            result.setKvTable(KVTable.decode(response.getBody(), KVTable.class));
        }
        return result;
    }
    default:
        break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}