当前位置: 首页>>代码示例>>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;未经允许,请勿转载。