org.apache.rocketmq.common.TopicConfig Java Examples

The following examples show how to use org.apache.rocketmq.common.TopicConfig. 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: MQAdminExtImpl.java    From rocketmq-exporter with Apache License 2.0 6 votes vote down vote up
@Override
public TopicConfig examineTopicConfig(String addr, String topic) {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);
    RemotingCommand response = null;
    try {
        response = remotingClient.invokeSync(addr, request, 3000);
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            TopicConfigSerializeWrapper topicConfigSerializeWrapper = decode(response.getBody(), TopicConfigSerializeWrapper.class);
            return topicConfigSerializeWrapper.getTopicConfigTable().get(topic);
        }
        default:
            throw Throwables.propagate(new MQBrokerException(response.getCode(), response.getRemark()));
    }
}
 
Example #2
Source File: DefaultRequestProcessorTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private void registerRouteInfoManager() {
    TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
    ConcurrentHashMap<String, TopicConfig> topicConfigConcurrentHashMap = new ConcurrentHashMap<>();
    TopicConfig topicConfig = new TopicConfig();
    topicConfig.setWriteQueueNums(8);
    topicConfig.setTopicName("unit-test");
    topicConfig.setPerm(6);
    topicConfig.setReadQueueNums(8);
    topicConfig.setOrder(false);
    topicConfigConcurrentHashMap.put("unit-test", topicConfig);
    topicConfigSerializeWrapper.setTopicConfigTable(topicConfigConcurrentHashMap);
    Channel channel = mock(Channel.class);
    RegisterBrokerResult registerBrokerResult = routeInfoManager.registerBroker("default-cluster", "127.0.0.1:10911", "default-broker", 1234, "127.0.0.1:1001",
        topicConfigSerializeWrapper, new ArrayList<String>(), channel);

}
 
Example #3
Source File: TopicConfigManager.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void updateTopicUnitFlag(final String topic, final boolean unit) {

        TopicConfig topicConfig = this.topicConfigTable.get(topic);
        if (topicConfig != null) {
            int oldTopicSysFlag = topicConfig.getTopicSysFlag();
            if (unit) {
                topicConfig.setTopicSysFlag(TopicSysFlag.setUnitFlag(oldTopicSysFlag));
            } else {
                topicConfig.setTopicSysFlag(TopicSysFlag.clearUnitFlag(oldTopicSysFlag));
            }

            log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
                topicConfig.getTopicSysFlag());

            this.topicConfigTable.put(topic, topicConfig);

            this.dataVersion.nextVersion();

            this.persist();
            this.brokerController.registerBrokerAll(false, true, true);
        }
    }
 
Example #4
Source File: AdjustQueueNumStrategy.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
public boolean isCanAdjustReadQueueSize(String topic, int scaleQueueSize) {
    TopicConfig topicConfig = deFiBrokerController.getTopicConfigManager().getTopicConfigTable().get(topic);
    if (topicConfig != null) {
        for (int qId = scaleQueueSize; qId < topicConfig.getReadQueueNums(); qId++) {
            long maxOffsetInConsumeQueue = deFiBrokerController.getMessageStore().getMaxOffsetInQueue(topic, qId);
            long lastMsgTime = deFiBrokerController.getMessageStore().getMessageStoreTimeStamp(topic, qId, maxOffsetInConsumeQueue - 1);
            long diff = System.currentTimeMillis() - lastMsgTime;
            if (diff < 60 * 1000) {
                log.info("adjust queue num, still new message in within {} ms, default threshold 60000 ms", System.currentTimeMillis() - lastMsgTime);
                return false;
            }

            Set<String> topicConsumeByWho = this.deFiBrokerController.getConsumerManager().queryTopicConsumeByWho(topic);
            Set<String> groupInOffset = this.deFiBrokerController.getConsumerOffsetManager().whichGroupByTopic(topic);
            if (groupInOffset != null && !groupInOffset.isEmpty()) {
                topicConsumeByWho.addAll(groupInOffset);
            }
            boolean allConsumed = isAllMessageConsumed(topic, topicConsumeByWho, qId);
            if (!allConsumed) {
                return false;
            }
        }
        return true;
    }
    return false;
}
 
Example #5
Source File: RouteInfoManagerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegisterBroker() {
    TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
    ConcurrentHashMap<String, TopicConfig> topicConfigConcurrentHashMap = new ConcurrentHashMap<>();
    TopicConfig topicConfig = new TopicConfig();
    topicConfig.setWriteQueueNums(8);
    topicConfig.setTopicName("unit-test");
    topicConfig.setPerm(6);
    topicConfig.setReadQueueNums(8);
    topicConfig.setOrder(false);
    topicConfigConcurrentHashMap.put("unit-test", topicConfig);
    topicConfigSerializeWrapper.setTopicConfigTable(topicConfigConcurrentHashMap);
    Channel channel = mock(Channel.class);
    RegisterBrokerResult registerBrokerResult = routeInfoManager.registerBroker("default-cluster", "127.0.0.1:10911", "default-broker", 1234, "127.0.0.1:1001",
        topicConfigSerializeWrapper, new ArrayList<String>(), channel);
    assertThat(registerBrokerResult).isNotNull();
}
 
Example #6
Source File: PullMessageProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    brokerController.setMessageStore(messageStore);
    pullMessageProcessor = new PullMessageProcessor(brokerController);
    Channel mockChannel = mock(Channel.class);
    when(mockChannel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(handlerContext.channel()).thenReturn(mockChannel);
    brokerController.getTopicConfigManager().getTopicConfigTable().put(topic, new TopicConfig());
    clientChannelInfo = new ClientChannelInfo(mockChannel);
    ConsumerData consumerData = createConsumerData(group, topic);
    brokerController.getConsumerManager().registerConsumer(
        consumerData.getGroupName(),
        clientChannelInfo,
        consumerData.getConsumeType(),
        consumerData.getMessageModel(),
        consumerData.getConsumeFromWhere(),
        consumerData.getSubscriptionDataSet(),
        false);
}
 
Example #7
Source File: TopicConfigManager.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig != null) {
        int oldTopicSysFlag = topicConfig.getTopicSysFlag();
        if (hasUnitSub) {
            topicConfig.setTopicSysFlag(TopicSysFlag.setUnitSubFlag(oldTopicSysFlag));
        }

        log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
            topicConfig.getTopicSysFlag());

        this.topicConfigTable.put(topic, topicConfig);

        this.dataVersion.nextVersion();

        this.persist();
        this.brokerController.registerBrokerAll(false, true, true);
    }
}
 
Example #8
Source File: TopicConfigManager.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void updateTopicUnitFlag(final String topic, final boolean unit) {

        TopicConfig topicConfig = this.topicConfigTable.get(topic);
        if (topicConfig != null) {
            int oldTopicSysFlag = topicConfig.getTopicSysFlag();
            if (unit) {
                topicConfig.setTopicSysFlag(TopicSysFlag.setUnitFlag(oldTopicSysFlag));
            } else {
                topicConfig.setTopicSysFlag(TopicSysFlag.clearUnitFlag(oldTopicSysFlag));
            }

            log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
                topicConfig.getTopicSysFlag());

            this.topicConfigTable.put(topic, topicConfig);

            this.dataVersion.nextVersion();

            this.persist();
            this.brokerController.registerBrokerAll(false, true);
        }
    }
 
Example #9
Source File: TopicConfigManager.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig != null) {
        int oldTopicSysFlag = topicConfig.getTopicSysFlag();
        if (hasUnitSub) {
            topicConfig.setTopicSysFlag(TopicSysFlag.setUnitSubFlag(oldTopicSysFlag));
        }

        log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
            topicConfig.getTopicSysFlag());

        this.topicConfigTable.put(topic, topicConfig);

        this.dataVersion.nextVersion();

        this.persist();
        this.brokerController.registerBrokerAll(false, true);
    }
}
 
Example #10
Source File: TopicConfigManager.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
/**
 * 更新 topic 是否有单元化订阅组
 */
public void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig != null) {
        int oldTopicSysFlag = topicConfig.getTopicSysFlag();
        if (hasUnitSub) {
            topicConfig.setTopicSysFlag(TopicSysFlag.setUnitSubFlag(oldTopicSysFlag));
        }

        LOG.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
            topicConfig.getTopicSysFlag());

        this.topicConfigTable.put(topic, topicConfig);

        this.dataVersion.nextVersion();

        this.persist();
        this.brokerController.registerBrokerAll(false, true);
    }
}
 
Example #11
Source File: PullMessageProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    brokerController.setMessageStore(messageStore);
    pullMessageProcessor = new PullMessageProcessor(brokerController);
    Channel mockChannel = mock(Channel.class);
    when(mockChannel.remoteAddress()).thenReturn(new InetSocketAddress(1024));
    when(handlerContext.channel()).thenReturn(mockChannel);
    brokerController.getTopicConfigManager().getTopicConfigTable().put(topic, new TopicConfig());
    clientChannelInfo = new ClientChannelInfo(mockChannel);
    ConsumerData consumerData = createConsumerData(group, topic);
    brokerController.getConsumerManager().registerConsumer(
        consumerData.getGroupName(),
        clientChannelInfo,
        consumerData.getConsumeType(),
        consumerData.getMessageModel(),
        consumerData.getConsumeFromWhere(),
        consumerData.getSubscriptionDataSet(),
        false);
}
 
Example #12
Source File: TopicConfigManager.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
public void updateTopicUnitFlag(final String topic, final boolean unit) {

        TopicConfig topicConfig = this.topicConfigTable.get(topic);
        if (topicConfig != null) {
            int oldTopicSysFlag = topicConfig.getTopicSysFlag();
            if (unit) {
                topicConfig.setTopicSysFlag(TopicSysFlag.setUnitFlag(oldTopicSysFlag));
            } else {
                topicConfig.setTopicSysFlag(TopicSysFlag.clearUnitFlag(oldTopicSysFlag));
            }

            LOG.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
                topicConfig.getTopicSysFlag());

            this.topicConfigTable.put(topic, topicConfig);

            this.dataVersion.nextVersion();

            this.persist();
            this.brokerController.registerBrokerAll(false, true);
        }
    }
 
Example #13
Source File: DefaultRequestProcessorTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private void registerRouteInfoManager() {
    TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
    ConcurrentHashMap<String, TopicConfig> topicConfigConcurrentHashMap = new ConcurrentHashMap<>();
    TopicConfig topicConfig = new TopicConfig();
    topicConfig.setWriteQueueNums(8);
    topicConfig.setTopicName("unit-test");
    topicConfig.setPerm(6);
    topicConfig.setReadQueueNums(8);
    topicConfig.setOrder(false);
    topicConfigConcurrentHashMap.put("unit-test", topicConfig);
    topicConfigSerializeWrapper.setTopicConfigTable(topicConfigConcurrentHashMap);
    Channel channel = mock(Channel.class);
    RegisterBrokerResult registerBrokerResult = routeInfoManager.registerBroker("default-cluster", "127.0.0.1:10911", "127.0.0.1:10911","default-broker", 1234, "127.0.0.1:1001",
        topicConfigSerializeWrapper, new ArrayList<String>(), channel);

}
 
Example #14
Source File: TopicConfigManager.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig != null) {
        int oldTopicSysFlag = topicConfig.getTopicSysFlag();
        if (hasUnitSub) {
            topicConfig.setTopicSysFlag(TopicSysFlag.setUnitSubFlag(oldTopicSysFlag));
        }

        log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
            topicConfig.getTopicSysFlag());

        this.topicConfigTable.put(topic, topicConfig);

        this.dataVersion.nextVersion();

        this.persist();
        this.brokerController.registerBrokerAll(false, true,true);
    }
}
 
Example #15
Source File: RouteInfoManagerTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegisterBroker() {
    TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
    ConcurrentHashMap<String, TopicConfig> topicConfigConcurrentHashMap = new ConcurrentHashMap<>();
    TopicConfig topicConfig = new TopicConfig();
    topicConfig.setWriteQueueNums(8);
    topicConfig.setTopicName("unit-test");
    topicConfig.setPerm(6);
    topicConfig.setReadQueueNums(8);
    topicConfig.setOrder(false);
    topicConfigConcurrentHashMap.put("unit-test", topicConfig);
    topicConfigSerializeWrapper.setTopicConfigTable(topicConfigConcurrentHashMap);
    Channel channel = mock(Channel.class);
    RegisterBrokerResult registerBrokerResult = routeInfoManager.registerBroker("default-cluster", "127.0.0.1:10911", "default-broker", 1234, "127.0.0.1:1001",
        topicConfigSerializeWrapper, new ArrayList<String>(), channel);
    assertThat(registerBrokerResult).isNotNull();
}
 
Example #16
Source File: DefaultRequestProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private void registerRouteInfoManager() {
    TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
    ConcurrentHashMap<String, TopicConfig> topicConfigConcurrentHashMap = new ConcurrentHashMap<>();
    TopicConfig topicConfig = new TopicConfig();
    topicConfig.setWriteQueueNums(8);
    topicConfig.setTopicName("unit-test");
    topicConfig.setPerm(6);
    topicConfig.setReadQueueNums(8);
    topicConfig.setOrder(false);
    topicConfigConcurrentHashMap.put("unit-test", topicConfig);
    topicConfigSerializeWrapper.setTopicConfigTable(topicConfigConcurrentHashMap);
    Channel channel = mock(Channel.class);
    RegisterBrokerResult registerBrokerResult = routeInfoManager.registerBroker("default-cluster", "127.0.0.1:10911", "default-broker", 1234, "127.0.0.1:1001",
        topicConfigSerializeWrapper, new ArrayList<String>(), channel);

}
 
Example #17
Source File: TopicConfigManager.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void updateTopicUnitSubFlag(final String topic, final boolean hasUnitSub) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig != null) {
        int oldTopicSysFlag = topicConfig.getTopicSysFlag();
        if (hasUnitSub) {
            topicConfig.setTopicSysFlag(TopicSysFlag.setUnitSubFlag(oldTopicSysFlag));
        }

        log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag,
            topicConfig.getTopicSysFlag());

        this.topicConfigTable.put(topic, topicConfig);

        this.dataVersion.nextVersion();

        this.persist();
        this.brokerController.registerBrokerAll(false, true);
    }
}
 
Example #18
Source File: RegisterBrokerBody.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static ConcurrentMap<String, TopicConfig> cloneTopicConfigTable(
    ConcurrentMap<String, TopicConfig> topicConfigConcurrentMap) {
    ConcurrentHashMap<String, TopicConfig> result = new ConcurrentHashMap<String, TopicConfig>();
    if (topicConfigConcurrentMap != null) {
        for (Map.Entry<String, TopicConfig> entry : topicConfigConcurrentMap.entrySet()) {
            result.put(entry.getKey(), entry.getValue());
        }
    }
    return result;

}
 
Example #19
Source File: RouteInfoManager.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
private void createAndUpdateQueueData(final String brokerName, final TopicConfig topicConfig) {
    QueueData queueData = new QueueData();
    queueData.setBrokerName(brokerName);
    queueData.setWriteQueueNums(topicConfig.getWriteQueueNums());
    queueData.setReadQueueNums(topicConfig.getReadQueueNums());
    queueData.setPerm(topicConfig.getPerm());
    queueData.setTopicSynFlag(topicConfig.getTopicSysFlag());

    List<QueueData> queueDataList = this.topicQueueTable.get(topicConfig.getTopicName());
    if (null == queueDataList) {
        queueDataList = new LinkedList<QueueData>();
        queueDataList.add(queueData);
        this.topicQueueTable.put(topicConfig.getTopicName(), queueDataList);
        log.info("new topic registerd, {} {}", topicConfig.getTopicName(), queueData);
    } else {
        boolean addNewOne = true;

        Iterator<QueueData> it = queueDataList.iterator();
        while (it.hasNext()) {
            QueueData qd = it.next();
            if (qd.getBrokerName().equals(brokerName)) {
                if (qd.equals(queueData)) {
                    addNewOne = false;
                } else {
                    log.info("topic changed, {} OLD: {} NEW: {}", topicConfig.getTopicName(), qd,
                        queueData);
                    it.remove();
                }
            }
        }

        if (addNewOne) {
            queueDataList.add(queueData);
        }
    }
}
 
Example #20
Source File: ConsumeQueueManager.java    From DeFiBus with Apache License 2.0 5 votes vote down vote up
public void load() {
    deFiBrokerController.scheduleTaskAtFixedRate(() -> {
        LOG.debug("start to scheduleTask query ConsumeQueueWaterMark");
        Iterator<Map.Entry<TopicQueue, ConsumeQueueWaterMark>> iterator = tqMaxAccumulated.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<TopicQueue, ConsumeQueueWaterMark> entry = iterator.next();
            TopicQueue tq = entry.getKey();
            try {
                TopicConfig topicConfig = this.getBrokerController().getTopicConfigManager().selectTopicConfig(tq.topic);
                if (topicConfig == null) {
                    iterator.remove();
                    LOG.info("scan queue depth. topicConfig is null, remove {}", entry.getValue());
                } else if (tq.queueId >= topicConfig.getReadQueueNums()) {
                    iterator.remove();
                    LOG.info("scan queue depth. qId is invalid, topicConfig.ReadQueueNums={}, remove {}", topicConfig.getReadQueueNums(), entry.getValue());
                } else {
                    ConsumeQueueWaterMark consumeQueueWaterMark = ConsumeQueueManager.this.calculateMinAccumulated(tq.topic, tq.queueId);
                    if (consumeQueueWaterMark != null) {
                        ConsumeQueueWaterMark oldCqWm = tqMaxAccumulated.put(tq, consumeQueueWaterMark);
                        if (LOG.isDebugEnabled()) {
                            if (!consumeQueueWaterMark.equals(oldCqWm)) {
                                LOG.debug("[UPDATE ConsumeQueueWaterMark] Updated for {}, -> {}", tq, consumeQueueWaterMark);
                            } else {
                                LOG.debug("[UPDATE ConsumeQueueWaterMark] Does not changed for {}, {}, {} ", tq, oldCqWm, consumeQueueWaterMark);
                            }
                        }
                    } else {
                        LOG.warn("ConsumeQueueWaterMark is null for {} , remove it from tqMaxAccumulated", tq);
                    }
                }
            } catch (Exception e) {
                LOG.error("unknow error when update ConsumeQueueWaterMark for " + tq, e);
            }
        }
    }, 1000, deFiBrokerController.getDeFiBusBrokerConfig().getDepthCheckInterval());
}
 
Example #21
Source File: TopicConfigManager.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public boolean isOrderTopic(final String topic) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig == null) {
        return false;
    } else {
        return topicConfig.isOrder();
    }
}
 
Example #22
Source File: TopicConfigManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void deleteTopicConfig(final String topic) {
    TopicConfig old = this.topicConfigTable.remove(topic);
    if (old != null) {
        log.info("delete topic config OK, topic: {}", old);
        this.dataVersion.nextVersion();
        this.persist();
    } else {
        log.warn("delete topic config failed, topic: {} not exists", topic);
    }
}
 
Example #23
Source File: AdminBrokerProcessor.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
private RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final CreateTopicRequestHeader requestHeader =
        (CreateTopicRequestHeader) request.decodeCommandCustomHeader(CreateTopicRequestHeader.class);
    log.info("updateAndCreateTopic called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

    if (requestHeader.getTopic().equals(this.brokerController.getBrokerConfig().getBrokerClusterName())) {
        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;
    }

    try {
        response.setCode(ResponseCode.SUCCESS);
        response.setOpaque(request.getOpaque());
        response.markResponseType();
        response.setRemark(null);
        ctx.writeAndFlush(response);
    } catch (Exception e) {
        log.error("Failed to produce a proper response", e);
    }

    TopicConfig topicConfig = new TopicConfig(requestHeader.getTopic());
    topicConfig.setReadQueueNums(requestHeader.getReadQueueNums());
    topicConfig.setWriteQueueNums(requestHeader.getWriteQueueNums());
    topicConfig.setTopicFilterType(requestHeader.getTopicFilterTypeEnum());
    topicConfig.setPerm(requestHeader.getPerm());
    topicConfig.setTopicSysFlag(requestHeader.getTopicSysFlag() == null ? 0 : requestHeader.getTopicSysFlag());

    this.brokerController.getTopicConfigManager().updateTopicConfig(topicConfig);
    this.brokerController.registerBrokerAll(false, true);

    return null;
}
 
Example #24
Source File: TopicConfigManager.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public boolean isOrderTopic(final String topic) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig == null) {
        return false;
    } else {
        return topicConfig.isOrder();
    }
}
 
Example #25
Source File: TopicConfigManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public boolean isOrderTopic(final String topic) {
    TopicConfig topicConfig = this.topicConfigTable.get(topic);
    if (topicConfig == null) {
        return false;
    } else {
        return topicConfig.isOrder();
    }
}
 
Example #26
Source File: AbstractSendMessageProcessor.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
protected MessageExtBrokerInner buildInnerMsg(final ChannelHandlerContext ctx,
    final SendMessageRequestHeader requestHeader, final byte[] body, TopicConfig topicConfig) {
    int queueIdInt = requestHeader.getQueueId();
    if (queueIdInt < 0) {
        queueIdInt = Math.abs(this.random.nextInt() % 99999999) % topicConfig.getWriteQueueNums();
    }
    int sysFlag = requestHeader.getSysFlag();

    if (TopicFilterType.MULTI_TAG == topicConfig.getTopicFilterType()) {
        sysFlag |= MessageSysFlag.MULTI_TAGS_FLAG;
    }

    MessageExtBrokerInner msgInner = new MessageExtBrokerInner();
    msgInner.setTopic(requestHeader.getTopic());
    msgInner.setBody(body);
    msgInner.setFlag(requestHeader.getFlag());
    MessageAccessor.setProperties(msgInner,
        MessageDecoder.string2messageProperties(requestHeader.getProperties()));
    msgInner.setPropertiesString(requestHeader.getProperties());
    msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(topicConfig.getTopicFilterType(),
        msgInner.getTags()));

    msgInner.setQueueId(queueIdInt);
    msgInner.setSysFlag(sysFlag);
    msgInner.setBornTimestamp(requestHeader.getBornTimestamp());
    msgInner.setBornHost(ctx.channel().remoteAddress());
    msgInner.setStoreHost(this.getStoreHost());
    msgInner.setReconsumeTimes(requestHeader.getReconsumeTimes() == null ? 0 : requestHeader
        .getReconsumeTimes());
    return msgInner;
}
 
Example #27
Source File: TopicConfigManager.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 打印
 * @param tcs ;
 */
private void printLoadDataWhenFirstBoot(final TopicConfigSerializeWrapper tcs) {
    Iterator<Entry<String, TopicConfig>> it = tcs.getTopicConfigTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, TopicConfig> next = it.next();
        log.info("load exist local topic, {}", next.getValue().toString());
    }
}
 
Example #28
Source File: TransactionalMessageBridge.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public Set<MessageQueue> fetchMessageQueues(String topic) {
    Set<MessageQueue> mqSet = new HashSet<>();
    TopicConfig topicConfig = selectTopicConfig(topic);
    if (topicConfig != null && topicConfig.getReadQueueNums() > 0) {
        for (int i = 0; i < topicConfig.getReadQueueNums(); i++) {
            MessageQueue mq = new MessageQueue();
            mq.setTopic(topic);
            mq.setBrokerName(brokerController.getBrokerConfig().getBrokerName());
            mq.setQueueId(i);
            mqSet.add(mq);
        }
    }
    return mqSet;
}
 
Example #29
Source File: BrokerController.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public synchronized void registerBrokerAll(final boolean checkOrderConfig, boolean oneway, boolean forceRegister) {
//        包装topic配置信息
        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);
        }

//        判断broker集群是否需要注册=》
        if (forceRegister || needRegister(this.brokerConfig.getBrokerClusterName(),
            this.getBrokerAddr(),
            this.brokerConfig.getBrokerName(),
            this.brokerConfig.getBrokerId(),
            this.brokerConfig.getRegisterBrokerTimeoutMills())) {
//            向所有的broker注册topic配置信息 =》
            doRegisterBrokerAll(checkOrderConfig, oneway, topicConfigWrapper);
        }
    }
 
Example #30
Source File: RegisterBrokerBody.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static ConcurrentMap<String, TopicConfig> cloneTopicConfigTable(
    ConcurrentMap<String, TopicConfig> topicConfigConcurrentMap) {
    ConcurrentHashMap<String, TopicConfig> result = new ConcurrentHashMap<String, TopicConfig>();
    if (topicConfigConcurrentMap != null) {
        for (Map.Entry<String, TopicConfig> entry : topicConfigConcurrentMap.entrySet()) {
            result.put(entry.getKey(), entry.getValue());
        }
    }
    return result;

}