Java Code Examples for org.apache.rocketmq.common.TopicConfig#setReadQueueNums()

The following examples show how to use org.apache.rocketmq.common.TopicConfig#setReadQueueNums() . 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: 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 2
Source File: DefaultRequestProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private void registerRouteInfoManager(String brokerAddr, String brokerName, long brokerId, String topicName) {
    TopicConfigSerializeWrapper topicConfigSerializeWrapper = new TopicConfigSerializeWrapper();
    ConcurrentHashMap<String, TopicConfig> topicConfigConcurrentHashMap = new ConcurrentHashMap<>();
    TopicConfig topicConfig = new TopicConfig();
    topicConfig.setWriteQueueNums(8);
    topicConfig.setTopicName(topicName);
    topicConfig.setPerm(6);
    topicConfig.setReadQueueNums(8);
    topicConfig.setOrder(false);
    topicConfigConcurrentHashMap.put(topicName, topicConfig);
    topicConfigSerializeWrapper.setTopicConfigTable(topicConfigConcurrentHashMap);
    Channel channel = mock(Channel.class);
    RegisterBrokerResult registerBrokerResult = routeInfoManager.registerBroker("default-cluster", brokerAddr, brokerName, brokerId, "127.0.0.1:1001",
        0l,0l,topicConfigSerializeWrapper, new ArrayList<String>(), channel);

}
 
Example 3
Source File: RmqAdminServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private void createTopic(String rmqClusterName, MqServer mqServer, String topic, int readQueueNums, int writeQueueNums) throws MqException {
    DefaultMQAdminExt defaultMQAdminExt = getMQAdminExt(mqServer.getAddr());

    if (isTopicExist(topic, defaultMQAdminExt)) {
        LOGGER.info("rmq topic has exist, namesvr={}, topic={}", mqServer.getAddr(), topic);
        return;
    }

    try {
        Set<String> masterSet = getMasterBrokerByBrokerName(mqServer.getAddr(), rmqClusterName);

        TopicConfig topicConfig = new TopicConfig();
        topicConfig.setReadQueueNums(readQueueNums);
        topicConfig.setWriteQueueNums(writeQueueNums);
        topicConfig.setTopicName(topic);
        for (String addr : masterSet) {
            defaultMQAdminExt.createAndUpdateTopicConfig(addr, topicConfig);
        }
    } catch (Exception e) {
        LOGGER.error("[RMQ] createTopic exception, topic:" + topic + ", rmqClusterName:" + rmqClusterName, e);
        throw new MqException("[RMQ] create topic<" + topic + "> error:" + e.getMessage(), e);
    }
}
 
Example 4
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 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: 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 7
Source File: RouteInfoManagerTest.java    From rocketmq-read 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", "127.0.0.1:10911","default-broker", 1234, "127.0.0.1:1001",
        topicConfigSerializeWrapper, new ArrayList<String>(), channel);
    assertThat(registerBrokerResult).isNotNull();
}
 
Example 8
Source File: RmqAdminServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private void createTopic(String rmqClusterName, MqServer mqServer, String topic, int readQueueNums, int writeQueueNums) throws MqException {
    DefaultMQAdminExt defaultMQAdminExt = getMQAdminExt(mqServer.getAddr());

    if (isTopicExist(topic, defaultMQAdminExt)) {
        LOGGER.info("rmq topic has exist, namesvr={}, topic={}", mqServer.getAddr(), topic);
        return;
    }

    try {
        Set<String> masterSet = getMasterBrokerByBrokerName(mqServer.getAddr(), rmqClusterName);

        TopicConfig topicConfig = new TopicConfig();
        topicConfig.setReadQueueNums(readQueueNums);
        topicConfig.setWriteQueueNums(writeQueueNums);
        topicConfig.setTopicName(topic);
        for (String addr : masterSet) {
            defaultMQAdminExt.createAndUpdateTopicConfig(addr, topicConfig);
        }
    } catch (Exception e) {
        LOGGER.error("[RMQ] createTopic exception, topic:" + topic + ", rmqClusterName:" + rmqClusterName, e);
        throw new MqException("[RMQ] create topic<" + topic + "> error:" + e.getMessage(), e);
    }
}
 
Example 9
Source File: DeFiBrokerController.java    From DeFiBus with Apache License 2.0 6 votes vote down vote up
@Override
public boolean initialize() throws CloneNotSupportedException {
    boolean result = super.initialize();

    result = result && this.extTopicConfigManager.load();

    //reset the lastDeliverOffsetTable as offsetTable of consumer
    consumeQueueManager.load();

    String rrTopic = this.getBrokerConfig().getBrokerClusterName() + "-" + DeFiBusConstant.RR_REPLY_TOPIC;
    if (getTopicConfigManager().selectTopicConfig(rrTopic) == null) {
        TopicConfig topicConfig = new TopicConfig(rrTopic);
        topicConfig.setWriteQueueNums(1);
        topicConfig.setReadQueueNums(1);
        topicConfig.setPerm(PermName.PERM_INHERIT | PermName.PERM_READ | PermName.PERM_WRITE);
        this.getTopicConfigManager().updateTopicConfig(topicConfig);
    }
    this.getTopicConfigManager().getSystemTopic().add(rrTopic);

    return result;
}
 
Example 10
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 11
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 12
Source File: RouteInfoManagerTest.java    From DDMQ 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",
        1000L, 1000L, topicConfigSerializeWrapper, new ArrayList<String>(), channel);
    assertThat(registerBrokerResult).isNotNull();
}
 
Example 13
Source File: AdjustQueueNumStrategy.java    From DeFiBus with Apache License 2.0 5 votes vote down vote up
private TopicConfig generateNewTopicConfig(TopicConfig topicConfigOld, int writeQueueSize, int readQueueSize) {
    TopicConfig topicConfigNew = new TopicConfig();
    topicConfigNew.setPerm(topicConfigOld.getPerm());
    topicConfigNew.setTopicName(topicConfigOld.getTopicName());
    topicConfigNew.setWriteQueueNums(writeQueueSize);
    topicConfigNew.setReadQueueNums(readQueueSize);
    topicConfigNew.setOrder(topicConfigOld.isOrder());
    topicConfigNew.setTopicFilterType(topicConfigOld.getTopicFilterType());
    topicConfigNew.setTopicSysFlag(topicConfigOld.getTopicSysFlag());
    return topicConfigNew;
}
 
Example 14
Source File: AdminBrokerProcessor.java    From rocketmq-all-4.1.0-incubating 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 15
Source File: AdminBrokerProcessor.java    From rocketmq_trans_message 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) {
    }

    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 16
Source File: AdminBrokerProcessor.java    From rocketmq 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) {
    }

    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 17
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 18
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 19
Source File: DeFiAdminBrokerProcessor.java    From DeFiBus with Apache License 2.0 4 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.deFiBrokerController.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.deFiBrokerController.getTopicConfigManager().updateTopicConfig(topicConfig);

    //set topic queue depth
    HashMap<String, String> extFields = request.getExtFields();
    long maxLength = extFields.get("maxQueueDepth") == null ? DeFiBusTopicConfig.DEFAULT_QUEUE_LENGTH : Long.valueOf(extFields.get("maxQueueDepth"));
    this.deFiBrokerController.getExtTopicConfigManager().updateTopicConfig(
        new DeFiBusTopicConfig(requestHeader.getTopic(), maxLength));

    if (this.deFiBrokerController.getBrokerConfig().getBrokerId() != MixAll.MASTER_ID) {
        return null;
    }

    this.deFiBrokerController.registerIncrementBrokerData(topicConfig, this.deFiBrokerController.getTopicConfigManager().getDataVersion());

    this.deFiBrokerController.getConsumerManager().notifyWhenTopicConfigChange(requestHeader.getTopic());

    return null;
}
 
Example 20
Source File: AdminBrokerProcessor.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
/**
 * 更新或者创建topic
 * @param ctx ;
 * @param request ;
 * @return ;
 * @throws RemotingCommandException ;
 */
private synchronized 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()));

    //和系统topic冲突。BrokerClusterName
    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.registerIncrementBrokerData(topicConfig,this.brokerController.getTopicConfigManager().getDataVersion());

    return null;
}