com.alibaba.rocketmq.tools.command.CommandUtil Java Examples

The following examples show how to use com.alibaba.rocketmq.tools.command.CommandUtil. 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: TopicServiceImpl.java    From rocket-console with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteTopic(String topic, String clusterName) {
    try {
        if(StringUtils.isBlank(clusterName)){
            return deleteTopic(topic);
        }
        Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(mqAdminExt, clusterName);
        mqAdminExt.deleteTopicInBroker(masterSet, topic);
        Set<String> nameServerSet = null;
        if (StringUtils.isNotBlank(configureInitializer.getNameSrvAddr())) {
            String[] ns = configureInitializer.getNameSrvAddr().split(";");
            nameServerSet = new HashSet<String>(Arrays.asList(ns));
        }
        mqAdminExt.deleteTopicInNameServer(nameServerSet, topic);
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
    return true;
}
 
Example #2
Source File: TopicService.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@CmdTrace(cmdClazz = DeleteTopicSubCommand.class)
public boolean delete(String topicName, String clusterName) throws Throwable {
    Throwable t = null;
    DefaultMQAdminExt adminExt = getDefaultMQAdminExt();
    try {
        if (StringUtils.isNotBlank(clusterName)) {
            adminExt.start();
            Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(adminExt, clusterName);
            adminExt.deleteTopicInBroker(masterSet, topicName);
            Set<String> nameServerSet = null;
            if (StringUtils.isNotBlank(configureInitializer.getNamesrvAddr())) {
                String[] ns = configureInitializer.getNamesrvAddr().split(";");
                nameServerSet = new HashSet<String>(Arrays.asList(ns));
            }
            adminExt.deleteTopicInNameServer(nameServerSet, topicName);
            return true;
        }
        else {
            throw new IllegalStateException("clusterName is blank");
        }
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(adminExt);
    }
    throw t;
}
 
Example #3
Source File: ConsumerService.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@CmdTrace(cmdClazz = DeleteSubscriptionGroupCommand.class)
public boolean deleteSubGroup(String groupName, String brokerAddr, String clusterName) throws Throwable {
    Throwable t = null;
    DefaultMQAdminExt adminExt = getDefaultMQAdminExt();
    try {
        if (isNotBlank(brokerAddr)) {
            adminExt.start();

            adminExt.deleteSubscriptionGroup(brokerAddr, groupName);
            // System.out.printf("delete subscription group [%s] from broker [%s] success.\n",
            // groupName,addr);

            return true;
        }
        else if (isNotBlank(clusterName)) {
            adminExt.start();

            Set<String> masterSet = CommandUtil.fetchMasterAddrByClusterName(adminExt, clusterName);
            for (String master : masterSet) {
                adminExt.deleteSubscriptionGroup(master, groupName);
                // System.out.printf(
                // "delete subscription group [%s] from broker [%s] in cluster [%s] success.\n",
                // groupName, master, clusterName);
            }
            return true;
        }
        else {
            throw new IllegalStateException("brokerAddr or clusterName can not be all blank");
        }
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(adminExt);
    }
    throw t;
}
 
Example #4
Source File: BrokerService.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@CmdTrace(cmdClazz = UpdateBrokerConfigSubCommand.class)
public boolean updateBrokerConfig(String brokerAddr, String clusterName, String key, String value)
        throws Throwable {
    Throwable t = null;
    DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt();
    try {
        Properties properties = new Properties();
        properties.put(key, value);
        if (StringUtils.isNotBlank(brokerAddr)) {
            defaultMQAdminExt.start();
            defaultMQAdminExt.updateBrokerConfig(brokerAddr, properties);
            return true;
        }
        else if (StringUtils.isNotBlank(clusterName)) {
            defaultMQAdminExt.start();
            Set<String> masterSet =
                    CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName);
            for (String tempBrokerAddr : masterSet) {
                defaultMQAdminExt.updateBrokerConfig(tempBrokerAddr, properties);
            }
            return true;
        }
        else {
            throw new IllegalStateException("brokerAddr or clusterName can not be all blank");
        }
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(defaultMQAdminExt);
    }
    throw t;
}
 
Example #5
Source File: TopicService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@CmdTrace(cmdClazz = UpdateTopicSubCommand.class)
public boolean update(String topic, String readQueueNums, String writeQueueNums, String perm,
        String brokerAddr, String clusterName) throws Throwable {
    Throwable t = null;
    DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt();

    try {
        TopicConfig topicConfig = new TopicConfig();
        topicConfig.setReadQueueNums(8);
        topicConfig.setWriteQueueNums(8);
        topicConfig.setTopicName(topic);

        if (StringUtils.isNotBlank(readQueueNums)) {
            topicConfig.setReadQueueNums(Integer.parseInt(readQueueNums));
        }

        if (StringUtils.isNotBlank(writeQueueNums)) {
            topicConfig.setWriteQueueNums(Integer.parseInt(writeQueueNums));
        }

        if (StringUtils.isNotBlank(perm)) {
            topicConfig.setPerm(translatePerm(perm));
        }

        if (StringUtils.isNotBlank(brokerAddr)) {
            defaultMQAdminExt.start();
            defaultMQAdminExt.createAndUpdateTopicConfig(brokerAddr, topicConfig);
            return true;
        }
        else if (StringUtils.isNotBlank(clusterName)) {

            defaultMQAdminExt.start();

            Set<String> masterSet =
                    CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName);
            for (String addr : masterSet) {
                defaultMQAdminExt.createAndUpdateTopicConfig(addr, topicConfig);
            }
            return true;
        }
        else {
            throw new IllegalStateException("clusterName or brokerAddr can not be all blank");
        }
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(defaultMQAdminExt);
    }
    throw t;
}
 
Example #6
Source File: ConsumerService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@CmdTrace(cmdClazz = UpdateSubGroupSubCommand.class)
public boolean updateSubGroup(String brokerAddr, String clusterName, String groupName,
        String consumeEnable, String consumeFromMinEnable, String consumeBroadcastEnable,
        String retryQueueNums, String retryMaxTimes, String brokerId, String whichBrokerWhenConsumeSlowly)
        throws Throwable {
    Throwable t = null;
    DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt();

    try {
        SubscriptionGroupConfig subscriptionGroupConfig = new SubscriptionGroupConfig();
        subscriptionGroupConfig.setConsumeBroadcastEnable(false);
        subscriptionGroupConfig.setConsumeFromMinEnable(false);

        // groupName
        subscriptionGroupConfig.setGroupName(groupName);

        // consumeEnable
        if (isNotBlank(consumeEnable)) {
            subscriptionGroupConfig.setConsumeEnable(Boolean.parseBoolean(consumeEnable.trim()));
        }

        // consumeFromMinEnable
        if (isNotBlank(consumeFromMinEnable)) {
            subscriptionGroupConfig.setConsumeFromMinEnable(Boolean.parseBoolean(consumeFromMinEnable
                .trim()));
        }

        // consumeBroadcastEnable
        if (isNotBlank(consumeBroadcastEnable)) {
            subscriptionGroupConfig.setConsumeBroadcastEnable(Boolean.parseBoolean(consumeBroadcastEnable
                .trim()));
        }

        // retryQueueNums
        if (isNotBlank(retryQueueNums)) {
            subscriptionGroupConfig.setRetryQueueNums(Integer.parseInt(retryQueueNums.trim()));
        }

        // retryMaxTimes
        if (isNotBlank(retryMaxTimes)) {
            subscriptionGroupConfig.setRetryMaxTimes(Integer.parseInt(retryMaxTimes.trim()));
        }

        // brokerId
        if (isNotBlank(brokerId)) {
            subscriptionGroupConfig.setBrokerId(Long.parseLong(brokerId.trim()));
        }

        // whichBrokerWhenConsumeSlowly
        if (isNotBlank(whichBrokerWhenConsumeSlowly)) {
            subscriptionGroupConfig.setWhichBrokerWhenConsumeSlowly(Long
                .parseLong(whichBrokerWhenConsumeSlowly.trim()));
        }

        if (isNotBlank(brokerAddr)) {

            defaultMQAdminExt.start();

            defaultMQAdminExt.createAndUpdateSubscriptionGroupConfig(brokerAddr, subscriptionGroupConfig);
            // System.out.printf("create subscription group to %s success.\n",
            // addr);
            // System.out.println(subscriptionGroupConfig);
            return true;

        }
        else if (isNotBlank(clusterName)) {

            defaultMQAdminExt.start();

            Set<String> masterSet =
                    CommandUtil.fetchMasterAddrByClusterName(defaultMQAdminExt, clusterName);
            for (String addr : masterSet) {
                defaultMQAdminExt.createAndUpdateSubscriptionGroupConfig(addr, subscriptionGroupConfig);
                // System.out.printf("create subscription group to %s success.\n",
                // addr);
            }
            // System.out.println(subscriptionGroupConfig);
            return true;
        }
        else {
            throw new IllegalStateException("brokerAddr or clusterName can not be all blank");
        }

    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(defaultMQAdminExt);
    }

    throw t;
}