RocketMQ rocketmq-tools管理主题

RocketMQ rocketmq-tools管理主题

环境和软件版本

Win10IDEAJdk1.8rocketmq 5.1.3rocketmq-tools 5.1.3

引入依赖

xml 复制代码
<dependency>
    <groupId>org.apache.rocketmq</groupId>
    <artifactId>rocketmq-tools</artifactId>
    <version>5.1.3</version>
</dependency>

增删改查

  1. 启动rocketmq
sh 复制代码
mqnamersrv.cmd
mqbroker.cmd -n localhost:9876
  1. 测试代码

创建/更新主题

java 复制代码
    @Test
    @DisplayName("创建/修改主题")
    public void rocketMQCreateTopic() throws Exception {
        DefaultMQAdminExt adminExt = new DefaultMQAdminExt();
        adminExt.setNamesrvAddr("localhost:9876");
        adminExt.start();
        TopicConfig topicConfig = new TopicConfig();
        topicConfig.setTopicName("testTopic0");
        topicConfig.setReadQueueNums(8);
        topicConfig.setWriteQueueNums(8);
        topicConfig.setPerm(6);
        Set<String> brokerAddress = CommandUtil.fetchMasterAddrByClusterName(adminExt, "DefaultCluster");
        for (String address : brokerAddress) {
            System.out.printf("Broker地址:%s\n", address);
            adminExt.createAndUpdateTopicConfig(address, topicConfig);
        }
    }

查询主题

java 复制代码
    @Test
    @DisplayName("查询主题")
    public void rocketMQGetTopic() throws Exception {
        DefaultMQAdminExt adminExt = new DefaultMQAdminExt();
        adminExt.setNamesrvAddr("localhost:9876");
        adminExt.start();
        TopicList topicList = adminExt.fetchAllTopicList();
        Set<String> topicNameList = topicList.getTopicList();
        for (String topicName : topicNameList) {
            System.out.printf("主题:%s\n", topicName);
        }
    }

删除主题

java 复制代码
    @Test
    @DisplayName("删除主题")
    public void rocketMQDeleteTopic() throws Exception {
        DefaultMQAdminExt adminExt = new DefaultMQAdminExt();
        adminExt.setNamesrvAddr("localhost:9876");
        adminExt.start();
        adminExt.deleteTopic("testTopic0", "DefaultCluster");
        // 删除之后再查一遍
        TopicList topicList = adminExt.fetchAllTopicList();
        Set<String> topicNameList = topicList.getTopicList();
        for (String topicName : topicNameList) {
            System.out.printf("主题:%s\n", topicName);
        }
    }
相关推荐
小马爱打代码5 小时前
面试题-RocketMQ的基本架构、支持的消息模式、如何保证消息的可靠传输
架构·rocketmq
莱特昂11 小时前
K8S环境下验证RocketMQ扩缩容
kubernetes·rocketmq·java-rocketmq
Wang's Blog2 天前
RocketMQ: 保证消息的可靠性投递
rocketmq
Hello-Brand4 天前
RocketMQ系列1:基础介绍
消息队列·rocketmq·topic
qq_171538857 天前
探索 RocketMQ:企业级消息中间件的选择与应用
rocketmq
Wang's Blog10 天前
RocketMQ: Broker 使用指南
服务器·网络·rocketmq
可乐加.糖11 天前
RabbitMQ和RocketMQ相关面试题
java·rabbitmq·rocketmq·ruby·java-rabbitmq
BestandW1shEs12 天前
彻底理解消息队列的作用及如何选择
java·kafka·rabbitmq·rocketmq