當前位置: 首頁>>代碼示例>>Java>>正文


Java TopicSysFlag.buildSysFlag方法代碼示例

本文整理匯總了Java中com.alibaba.rocketmq.common.sysflag.TopicSysFlag.buildSysFlag方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSysFlag.buildSysFlag方法的具體用法?Java TopicSysFlag.buildSysFlag怎麽用?Java TopicSysFlag.buildSysFlag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.rocketmq.common.sysflag.TopicSysFlag的用法示例。


在下文中一共展示了TopicSysFlag.buildSysFlag方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: msgCheck

import com.alibaba.rocketmq.common.sysflag.TopicSysFlag; //導入方法依賴的package包/類
protected RemotingCommand msgCheck(final ChannelHandlerContext ctx,
        final SendMessageRequestHeader requestHeader, final RemotingCommand response) {
    //檢查broker的寫權限。
    if (!PermName.isWriteable(this.brokerController.getBrokerConfig().getBrokerPermission())
            && this.brokerController.getTopicConfigManager().isOrderTopic(requestHeader.getTopic())) {
        response.setCode(ResponseCode.NO_PERMISSION);
        response.setRemark("the broker[" + this.brokerController.getBrokerConfig().getBrokerIP1()
                + "] sending message is forbidden");
        return response;
    }
    //檢查topic和係統保留的topic名字是否衝突。
    if (!this.brokerController.getTopicConfigManager().isTopicCanSendMessage(requestHeader.getTopic())) {
        String errorMsg =
                "the topic[" + requestHeader.getTopic() + "] is conflict with system reserved words.";
        log.warn(errorMsg);
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(errorMsg);
        return response;
    }

    TopicConfig topicConfig =
            this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic());
    if (null == topicConfig) {
        int topicSysFlag = 0;
        if (requestHeader.isUnitMode()) {
            if (requestHeader.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) { //發給重試隊列
                topicSysFlag = TopicSysFlag.buildSysFlag(false, true);
            }
            else {
                topicSysFlag = TopicSysFlag.buildSysFlag(true, false);
            }
        }

        log.warn("the topic " + requestHeader.getTopic() + " not exist, producer: "
                + ctx.channel().remoteAddress());
        //未找到topic ,則用默認的topic:TBW102  的配置來創建一個topic.
        //如果客戶端投遞消息過來的時候,發現該topic不存在,則默認創建一個topic
        topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageMethod(//
            requestHeader.getTopic(), //
            requestHeader.getDefaultTopic(), //
            RemotingHelper.parseChannelRemoteAddr(ctx.channel()), //
            requestHeader.getDefaultTopicQueueNums(), topicSysFlag);

        if (null == topicConfig) {
            if (requestHeader.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
                topicConfig =
                        this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(
                            requestHeader.getTopic(), 1, PermName.PERM_WRITE | PermName.PERM_READ,
                            topicSysFlag);
            }
        }

        if (null == topicConfig) {
            response.setCode(ResponseCode.TOPIC_NOT_EXIST);
            response.setRemark("topic[" + requestHeader.getTopic() + "] not exist, apply first please!"
                    + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL));
            return response;
        }
    }

    int queueIdInt = requestHeader.getQueueId();
    int idValid = Math.max(topicConfig.getWriteQueueNums(), topicConfig.getReadQueueNums());
    if (queueIdInt >= idValid) { //隊列id 超過了讀寫隊列的最大ID。
        String errorInfo = String.format("request queueId[%d] is illagal, %s Producer: %s",//
            queueIdInt,//
            topicConfig.toString(),//
            RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

        log.warn(errorInfo);
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(errorInfo);

        return response;
    }
    return response;
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:77,代碼來源:AbstractSendMessageProcessor.java


注:本文中的com.alibaba.rocketmq.common.sysflag.TopicSysFlag.buildSysFlag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。