org.apache.rocketmq.common.protocol.route.BrokerData Java Examples

The following examples show how to use org.apache.rocketmq.common.protocol.route.BrokerData. 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: DefaultMQAdminExtImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException,
    InterruptedException, MQBrokerException {
    String retryTopic = MixAll.getRetryTopic(consumerGroup);
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic);
    ConsumeStats result = new ConsumeStats();

    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            ConsumeStats consumeStats =
                this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, topic, timeoutMillis * 3);
            result.getOffsetTable().putAll(consumeStats.getOffsetTable());
            double value = result.getConsumeTps() + consumeStats.getConsumeTps();
            result.setConsumeTps(value);
        }
    }

    if (result.getOffsetTable().isEmpty()) {
        throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE,
            "Not found the consumer group consume stats, because return offset table is empty, maybe the consumer not consume any message");
    }

    return result;
}
 
Example #2
Source File: DefaultMQAdminExtImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Override
public ConsumerConnection examineConsumerConnectionInfo(
    String consumerGroup) throws InterruptedException, MQBrokerException,
    RemotingException, MQClientException {
    ConsumerConnection result = new ConsumerConnection();
    String topic = MixAll.getRetryTopic(consumerGroup);
    List<BrokerData> brokers = this.examineTopicRouteInfo(topic).getBrokerDatas();
    BrokerData brokerData = brokers.get(random.nextInt(brokers.size()));
    String addr = null;
    if (brokerData != null) {
        addr = brokerData.selectBrokerAddr();
        if (StringUtils.isNotBlank(addr)) {
            result = this.mqClientInstance.getMQClientAPIImpl().getConsumerConnectionList(addr, consumerGroup, timeoutMillis);
        }
    }

    if (result.getConnectionSet().isEmpty()) {
        log.warn("the consumer group not online. brokerAddr={}, group={}", addr, consumerGroup);
        throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE, "Not found the consumer group connection");
    }

    return result;
}
 
Example #3
Source File: MQClientInstance.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private boolean isBrokerAddrExistInTopicRouteTable(final String addr) {
    Iterator<Entry<String, TopicRouteData>> it = this.topicRouteTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, TopicRouteData> entry = it.next();
        TopicRouteData topicRouteData = entry.getValue();
        List<BrokerData> bds = topicRouteData.getBrokerDatas();
        for (BrokerData bd : bds) {
            if (bd.getBrokerAddrs() != null) {
                boolean exist = bd.getBrokerAddrs().containsValue(addr);
                if (exist) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example #4
Source File: CommandUtil.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static Set<String> fetchMasterAddrByClusterName(final MQAdminExt adminExt, final String clusterName)
    throws InterruptedException, RemotingConnectException, RemotingTimeoutException,
    RemotingSendRequestException, MQBrokerException {
    Set<String> masterSet = new HashSet<String>();

    ClusterInfo clusterInfoSerializeWrapper = adminExt.examineBrokerClusterInfo();

    Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName);

    if (brokerNameSet != null) {
        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {

                String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (addr != null) {
                    masterSet.add(addr);
                }
            }
        }
    } else {
        System.out.printf("[error] %s", ERROR_MESSAGE);
    }

    return masterSet;
}
 
Example #5
Source File: DefaultMQAdminExtImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Override
public ProducerConnection examineProducerConnectionInfo(String producerGroup,
    final String topic) throws RemotingException,
    MQClientException, InterruptedException, MQBrokerException {
    ProducerConnection result = new ProducerConnection();
    List<BrokerData> brokers = this.examineTopicRouteInfo(topic).getBrokerDatas();
    BrokerData brokerData = brokers.get(random.nextInt(brokers.size()));
    String addr = null;
    if (brokerData != null) {
        addr = brokerData.selectBrokerAddr();
        if (StringUtils.isNotBlank(addr)) {
            result = this.mqClientInstance.getMQClientAPIImpl().getProducerConnectionList(addr, producerGroup, timeoutMillis);
        }
    }

    if (result.getConnectionSet().isEmpty()) {
        log.warn("the producer group not online. brokerAddr={}, group={}", addr, producerGroup);
        throw new MQClientException("Not found the producer group connection", null);
    }

    return result;
}
 
Example #6
Source File: DefaultMQAdminExtImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public Map<MessageQueue, Long> resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce,
    boolean isC)
    throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    Map<MessageQueue, Long> allOffsetTable = new HashMap<MessageQueue, Long>();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                Map<MessageQueue, Long> offsetTable =
                    this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce,
                        timeoutMillis, isC);
                if (offsetTable != null) {
                    allOffsetTable.putAll(offsetTable);
                }
            }
        }
    }
    return allOffsetTable;
}
 
Example #7
Source File: TopicListSubCommand.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private String findTopicBelongToWhichCluster(final String topic, final ClusterInfo clusterInfo,
    final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException,
    InterruptedException {
    TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);

    BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);

    String brokerName = brokerData.getBrokerName();

    Iterator<Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Set<String>> next = it.next();
        if (next.getValue().contains(brokerName)) {
            return next.getKey();
        }
    }
    return null;
}
 
Example #8
Source File: DefaultMQAdminExtImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException,
    MQBrokerException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    TopicStatsTable topicStatsTable = new TopicStatsTable();

    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            TopicStatsTable tst = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis);
            topicStatsTable.getOffsetTable().putAll(tst.getOffsetTable());
        }
    }

    if (topicStatsTable.getOffsetTable().isEmpty()) {
        throw new MQClientException("Not found the topic stats info", null);
    }

    return topicStatsTable;
}
 
Example #9
Source File: MQClientInstance.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private boolean isBrokerAddrExistInTopicRouteTable(final String addr) {
    Iterator<Entry<String, TopicRouteData>> it = this.topicRouteTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, TopicRouteData> entry = it.next();
        TopicRouteData topicRouteData = entry.getValue();
        List<BrokerData> bds = topicRouteData.getBrokerDatas();
        for (BrokerData bd : bds) {
            if (bd.getBrokerAddrs() != null) {
                boolean exist = bd.getBrokerAddrs().containsValue(addr);
                if (exist)
                    return true;
            }
        }
    }

    return false;
}
 
Example #10
Source File: DefaultMQAdminExtImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Override
public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId, boolean jstack) throws RemotingException,
    MQClientException, InterruptedException {
    String topic = MixAll.RETRY_GROUP_TOPIC_PREFIX + consumerGroup;
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                return this.mqClientInstance.getMQClientAPIImpl().getConsumerRunningInfo(addr, consumerGroup, clientId, jstack,
                    timeoutMillis * 3);
            }
        }
    }
    return null;
}
 
Example #11
Source File: DefaultMQProducerTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public static TopicRouteData createTopicRoute() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);
    return topicRouteData;
}
 
Example #12
Source File: RmqAdminServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private Set<String> getMasterBrokerByBrokerName(String nameServer, String rmqClusterName) throws Exception {
    ClusterInfo clusterInfoSerializeWrapper = examineBrokerClusterInfo(nameServer);
    Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(rmqClusterName);

    if (brokerNameSet == null) {
        throw new RuntimeException("Make sure the specified clusterName exists or the nameserver which connected is correct");
    }

    Set<String> masterSet = Sets.newHashSet();

    for (String brokerName : brokerNameSet) {
        BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
        if (brokerData != null) {
            String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
            if (addr != null) {
                masterSet.add(addr);
            }
        }
    }

    return masterSet;
}
 
Example #13
Source File: DefaultMQAdminExtImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public ProducerConnection examineProducerConnectionInfo(String producerGroup,
    final String topic) throws RemotingException,
    MQClientException, InterruptedException, MQBrokerException {
    ProducerConnection result = new ProducerConnection();
    List<BrokerData> brokers = this.examineTopicRouteInfo(topic).getBrokerDatas();
    BrokerData brokerData = brokers.get(random.nextInt(brokers.size()));
    String addr = null;
    if (brokerData != null) {
        addr = brokerData.selectBrokerAddr();
        if (StringUtils.isNotBlank(addr)) {
            result = this.mqClientInstance.getMQClientAPIImpl().getProducerConnectionList(addr, producerGroup, timeoutMillis);
        }
    }

    if (result.getConnectionSet().isEmpty()) {
        log.warn("the producer group not online. brokerAddr={}, group={}", addr, producerGroup);
        throw new MQClientException("Not found the producer group connection", null);
    }

    return result;
}
 
Example #14
Source File: DefaultMQAdminExtImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Override
public TopicStatsTable examineTopicStats(
    String topic) throws RemotingException, MQClientException, InterruptedException,
    MQBrokerException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    TopicStatsTable topicStatsTable = new TopicStatsTable();

    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            TopicStatsTable tst = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis);
            topicStatsTable.getOffsetTable().putAll(tst.getOffsetTable());
        }
    }

    if (topicStatsTable.getOffsetTable().isEmpty()) {
        throw new MQClientException("Not found the topic stats info", null);
    }

    return topicStatsTable;
}
 
Example #15
Source File: DefaultMQAdminExtImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public Map<MessageQueue, Long> resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC)
    throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    Map<MessageQueue, Long> allOffsetTable = new HashMap<MessageQueue, Long>();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                Map<MessageQueue, Long> offsetTable =
                    this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce,
                        timeoutMillis, isC);
                if (offsetTable != null) {
                    allOffsetTable.putAll(offsetTable);
                }
            }
        }
    }
    return allOffsetTable;
}
 
Example #16
Source File: DefaultRequestProcessorTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessRequest_RegisterBroker() throws RemotingCommandException,
    NoSuchFieldException, IllegalAccessException {
    RemotingCommand request = genSampleRegisterCmd(true);

    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    when(ctx.channel()).thenReturn(null);

    RemotingCommand response = defaultRequestProcessor.processRequest(ctx, request);

    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(response.getRemark()).isNull();

    RouteInfoManager routes = namesrvController.getRouteInfoManager();
    Field brokerAddrTable = RouteInfoManager.class.getDeclaredField("brokerAddrTable");
    brokerAddrTable.setAccessible(true);

    BrokerData broker = new BrokerData();
    broker.setBrokerName("broker");
    broker.setBrokerAddrs((HashMap) Maps.newHashMap(new Long(2333), "10.10.1.1"));

    assertThat((Map) brokerAddrTable.get(routes))
        .contains(new HashMap.SimpleEntry("broker", broker));
}
 
Example #17
Source File: DefaultMQProducerTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static TopicRouteData createTopicRoute() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);
    return topicRouteData;
}
 
Example #18
Source File: DefaultMQAdminExtTest.java    From rocketmq_trans_message with Apache License 2.0 6 votes vote down vote up
@Test
public void testExamineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
    HashMap<String, BrokerData> brokerList = clusterInfo.getBrokerAddrTable();
    assertThat(brokerList.get("default-broker").getBrokerName()).isEqualTo("default-broker");
    assertThat(brokerList.containsKey("broker-test")).isTrue();

    HashMap<String, Set<String>> clusterMap = new HashMap<>();
    Set<String> brokers = new HashSet<>();
    brokers.add("default-broker");
    brokers.add("broker-test");
    clusterMap.put("default-cluster", brokers);
    ClusterInfo cInfo = mock(ClusterInfo.class);
    when(cInfo.getClusterAddrTable()).thenReturn(clusterMap);
    HashMap<String, Set<String>> clusterAddress = cInfo.getClusterAddrTable();
    assertThat(clusterAddress.containsKey("default-cluster")).isTrue();
    assertThat(clusterAddress.get("default-cluster").size()).isEqualTo(2);
}
 
Example #19
Source File: DefaultMQAdminExtImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public Map<MessageQueue, Long> resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce,
    boolean isC)
    throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    Map<MessageQueue, Long> allOffsetTable = new HashMap<MessageQueue, Long>();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                Map<MessageQueue, Long> offsetTable =
                    this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce,
                        timeoutMillis, isC);
                if (offsetTable != null) {
                    allOffsetTable.putAll(offsetTable);
                }
            }
        }
    }
    return allOffsetTable;
}
 
Example #20
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public Map<MessageQueue, Long> resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce,
    boolean isC)
    throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    Map<MessageQueue, Long> allOffsetTable = new HashMap<MessageQueue, Long>();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                Map<MessageQueue, Long> offsetTable =
                    this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce,
                        timeoutMillis, isC);
                if (offsetTable != null) {
                    allOffsetTable.putAll(offsetTable);
                }
            }
        }
    }
    return allOffsetTable;
}
 
Example #21
Source File: DefaultMQAdminExtTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testExamineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
    HashMap<String, BrokerData> brokerList = clusterInfo.getBrokerAddrTable();
    assertThat(brokerList.get("default-broker").getBrokerName()).isEqualTo("default-broker");
    assertThat(brokerList.containsKey("broker-test")).isTrue();

    HashMap<String, Set<String>> clusterMap = new HashMap<>();
    Set<String> brokers = new HashSet<>();
    brokers.add("default-broker");
    brokers.add("broker-test");
    clusterMap.put("default-cluster", brokers);
    ClusterInfo cInfo = mock(ClusterInfo.class);
    when(cInfo.getClusterAddrTable()).thenReturn(clusterMap);
    HashMap<String, Set<String>> clusterAddress = cInfo.getClusterAddrTable();
    assertThat(clusterAddress.containsKey("default-cluster")).isTrue();
    assertThat(clusterAddress.get("default-cluster").size()).isEqualTo(2);
}
 
Example #22
Source File: TopicListSubCommand.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private String findTopicBelongToWhichCluster(final String topic, final ClusterInfo clusterInfo,
    final DefaultMQAdminExt defaultMQAdminExt) throws RemotingException, MQClientException,
    InterruptedException {
    TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);

    BrokerData brokerData = topicRouteData.getBrokerDatas().get(0);

    String brokerName = brokerData.getBrokerName();

    Iterator<Entry<String, Set<String>>> it = clusterInfo.getClusterAddrTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, Set<String>> next = it.next();
        if (next.getValue().contains(brokerName)) {
            return next.getKey();
        }
    }
    return null;
}
 
Example #23
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId,
    boolean jstack) throws RemotingException,
    MQClientException, InterruptedException {
    String topic = MixAll.RETRY_GROUP_TOPIC_PREFIX + consumerGroup;
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                return this.mqClientInstance.getMQClientAPIImpl().getConsumerRunningInfo(addr, consumerGroup, clientId, jstack,
                    timeoutMillis * 3);
            }
        }
    }
    return null;
}
 
Example #24
Source File: DefaultRequestProcessorTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcessRequest_RegisterBroker() throws RemotingCommandException,
    NoSuchFieldException, IllegalAccessException {
    RemotingCommand request = genSampleRegisterCmd(true);

    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    when(ctx.channel()).thenReturn(null);

    RemotingCommand response = defaultRequestProcessor.processRequest(ctx, request);

    assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
    assertThat(response.getRemark()).isNull();

    RouteInfoManager routes = namesrvController.getRouteInfoManager();
    Field brokerAddrTable = RouteInfoManager.class.getDeclaredField("brokerAddrTable");
    brokerAddrTable.setAccessible(true);

    BrokerData broker = new BrokerData();
    broker.setBrokerName("broker");
    broker.setBrokerAddrs((HashMap) Maps.newHashMap(new Long(2333), "10.10.1.1"));

    assertThat((Map) brokerAddrTable.get(routes))
        .contains(new HashMap.SimpleEntry("broker", broker));
}
 
Example #25
Source File: DefaultMQProducerTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static TopicRouteData createTopicRoute() {
    TopicRouteData topicRouteData = new TopicRouteData();

    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    List<BrokerData> brokerDataList = new ArrayList<>();
    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerName("BrokerA");
    brokerData.setCluster("DefaultCluster");
    HashMap<Long, String> brokerAddrs = new HashMap<>();
    brokerAddrs.put(0L, "127.0.0.1:10911");
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerDataList.add(brokerData);
    topicRouteData.setBrokerDatas(brokerDataList);

    List<QueueData> queueDataList = new ArrayList<>();
    QueueData queueData = new QueueData();
    queueData.setBrokerName("BrokerA");
    queueData.setPerm(6);
    queueData.setReadQueueNums(3);
    queueData.setWriteQueueNums(4);
    queueData.setTopicSynFlag(0);
    queueDataList.add(queueData);
    topicRouteData.setQueueDatas(queueDataList);
    return topicRouteData;
}
 
Example #26
Source File: DefaultMQAdminExtTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testExamineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException {
    ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
    HashMap<String, BrokerData> brokerList = clusterInfo.getBrokerAddrTable();
    assertThat(brokerList.get("default-broker").getBrokerName()).isEqualTo("default-broker");
    assertThat(brokerList.containsKey("broker-test")).isTrue();

    HashMap<String, Set<String>> clusterMap = new HashMap<>();
    Set<String> brokers = new HashSet<>();
    brokers.add("default-broker");
    brokers.add("broker-test");
    clusterMap.put("default-cluster", brokers);
    ClusterInfo cInfo = mock(ClusterInfo.class);
    when(cInfo.getClusterAddrTable()).thenReturn(clusterMap);
    HashMap<String, Set<String>> clusterAddress = cInfo.getClusterAddrTable();
    assertThat(clusterAddress.containsKey("default-cluster")).isTrue();
    assertThat(clusterAddress.get("default-cluster").size()).isEqualTo(2);
}
 
Example #27
Source File: DefaultMQAdminExtImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException,
    InterruptedException, MQBrokerException {
    String retryTopic = MixAll.getRetryTopic(consumerGroup);
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic);
    ConsumeStats result = new ConsumeStats();

    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            ConsumeStats consumeStats =
                this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, topic, timeoutMillis * 3);
            result.getOffsetTable().putAll(consumeStats.getOffsetTable());
            double value = result.getConsumeTps() + consumeStats.getConsumeTps();
            result.setConsumeTps(value);
        }
    }

    if (result.getOffsetTable().isEmpty()) {
        throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE,
            "Not found the consumer group consume stats, because return offset table is empty, maybe the consumer not consume any message");
    }

    return result;
}
 
Example #28
Source File: MQAdmin.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static boolean isBrokerExist(String ns, String ip) {
    ClusterInfo clusterInfo = getCluster(ns);
    if (clusterInfo == null) {
        return false;
    } else {
        HashMap<String, BrokerData> brokers = clusterInfo.getBrokerAddrTable();
        for (String brokerName : brokers.keySet()) {
            HashMap<Long, String> brokerIps = brokers.get(brokerName).getBrokerAddrs();
            for (long brokerId : brokerIps.keySet()) {
                if (brokerIps.get(brokerId).contains(ip))
                    return true;
            }
        }
    }

    return false;
}
 
Example #29
Source File: MQClientInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public String findBrokerAddrByTopic(final String topic) {
    TopicRouteData topicRouteData = this.topicRouteTable.get(topic);
    if (topicRouteData != null) {
        List<BrokerData> brokers = topicRouteData.getBrokerDatas();
        if (!brokers.isEmpty()) {
            int index = random.nextInt(brokers.size());
            BrokerData bd = brokers.get(index % brokers.size());
            return bd.selectBrokerAddr();
        }
    }

    return null;
}
 
Example #30
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private boolean isBrokerInNameServer(final String brokerAddr) {
    Iterator<Entry<String, TopicRouteData>> it = this.topicRouteTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, TopicRouteData> itNext = it.next();
        List<BrokerData> brokerDatas = itNext.getValue().getBrokerDatas();
        for (BrokerData bd : brokerDatas) {
            boolean contain = bd.getBrokerAddrs().containsValue(brokerAddr);
            if (contain)
                return true;
        }
    }

    return false;
}