com.alibaba.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely Java Examples

The following examples show how to use com.alibaba.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely. 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: AllocateMessageQueueAveragelyTest.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllocate() {
    AllocateMessageQueueAveragely allocateMessageQueueAveragely = new AllocateMessageQueueAveragely();
    String topic = "topic_test";
    String currentCID = "CID";
    int queueSize = 19;
    int consumerSize = 10;
    List<MessageQueue> mqAll = new ArrayList<MessageQueue>();
    for (int i = 0; i < queueSize; i++) {
        MessageQueue mq = new MessageQueue(topic, "brokerName", i);
        mqAll.add(mq);
    }

    List<String> cidAll = new ArrayList<String>();
    for (int j = 0; j < consumerSize; j++) {
        cidAll.add("CID" + j);
    }
    System.out.println(mqAll.toString());
    System.out.println(cidAll.toString());
    for (int i = 0; i < consumerSize; i++) {
        List<MessageQueue> rs = allocateMessageQueueAveragely.allocate("", currentCID + i, mqAll, cidAll);
        System.out.println("rs[" + currentCID + i + "]:" + rs.toString());
    }
}
 
Example #2
Source File: AllocateMessageQueueAveragelyTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAllocate() {
    AllocateMessageQueueAveragely allocateMessageQueueAveragely = new AllocateMessageQueueAveragely();
    String topic = "topic_test";
    String currentCID = "CID";
    int queueSize = 19;
    int consumerSize = 10;
    List<MessageQueue> mqAll = new ArrayList<MessageQueue>();
    for (int i = 0; i < queueSize; i++) {
        MessageQueue mq = new MessageQueue(topic, "brokerName", i);
        mqAll.add(mq);
    }

    List<String> cidAll = new ArrayList<String>();
    for (int j = 0; j < consumerSize; j++) {
        cidAll.add("CID" + j);
    }
    System.out.println(mqAll.toString());
    System.out.println(cidAll.toString());
    for (int i = 0; i < consumerSize; i++) {
        List<MessageQueue> rs = allocateMessageQueueAveragely.allocate("", currentCID + i, mqAll, cidAll);
        System.out.println("rs[" + currentCID + i + "]:" + rs.toString());
    }
}
 
Example #3
Source File: AllocateMessageQueueAveragelyTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllocate() {
    AllocateMessageQueueAveragely allocateMessageQueueAveragely = new AllocateMessageQueueAveragely();
    String topic = "topic_test";
    String currentCID = "CID";
    int queueSize = 19;
    int consumerSize = 10;
    List<MessageQueue> mqAll = new ArrayList<MessageQueue>();
    for (int i = 0; i < queueSize; i++) {
        MessageQueue mq = new MessageQueue(topic, "brokerName", i);
        mqAll.add(mq);
    }

    List<String> cidAll = new ArrayList<String>();
    for (int j = 0; j < consumerSize; j++) {
        cidAll.add("CID" + j);
    }
    System.out.println(mqAll.toString());
    System.out.println(cidAll.toString());
    for (int i = 0; i < consumerSize; i++) {
        List<MessageQueue> rs = allocateMessageQueueAveragely.allocate("", currentCID + i, mqAll, cidAll);
        System.out.println("rs[" + currentCID + i + "]:" + rs.toString());
    }
}
 
Example #4
Source File: AllocateMQSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        adminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        String ips = commandLine.getOptionValue('i').trim();
        final String[] split = ips.split(",");
        final List<String> ipList = new LinkedList<String>();
        for (String ip : split) {
            ipList.add(ip);
        }

        final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic);
        final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData);

        final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely();


        RebalanceResult rr = new RebalanceResult();

        for (String i : ipList) {
            final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList);
            rr.getResult().put(i, mqResult);
        }

        final String json = RemotingSerializable.toJson(rr, false);
        System.out.println(json);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        adminExt.shutdown();
    }
}
 
Example #5
Source File: AllocateMQSubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt adminExt = new DefaultMQAdminExt(rpcHook);
    adminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        adminExt.start();

        String topic = commandLine.getOptionValue('t').trim();
        String ips = commandLine.getOptionValue('i').trim();
        final String[] split = ips.split(",");
        final List<String> ipList = new LinkedList<String>();
        for (String ip : split) {
            ipList.add(ip);
        }

        final TopicRouteData topicRouteData = adminExt.examineTopicRouteInfo(topic);
        final Set<MessageQueue> mqs = MQClientInstance.topicRouteData2TopicSubscribeInfo(topic, topicRouteData);

        final AllocateMessageQueueAveragely averagely = new AllocateMessageQueueAveragely();


        RebalanceResult rr = new RebalanceResult();

        for (String i : ipList) {
            final List<MessageQueue> mqResult = averagely.allocate("aa", i, new ArrayList<MessageQueue>(mqs), ipList);
            rr.getResult().put(i, mqResult);
        }

        final String json = RemotingSerializable.toJson(rr, false);
        System.out.println(json);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        adminExt.shutdown();
    }
}
 
Example #6
Source File: DefaultMQPushConsumer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public DefaultMQPushConsumer(final String consumerGroup) {
    this(consumerGroup, null, new AllocateMessageQueueAveragely());
}
 
Example #7
Source File: AllocateMessageQueueAveragelyTest.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Before
public void init() {
    allocateMessageQueueAveragely = new AllocateMessageQueueAveragely();
    topic = "topic_test";
}
 
Example #8
Source File: DefaultMQPushConsumer.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public DefaultMQPushConsumer(final String consumerGroup) {
    this(consumerGroup, null, new AllocateMessageQueueAveragely());
}
 
Example #9
Source File: DefaultMQPushConsumer.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public DefaultMQPushConsumer(RPCHook rpcHook) {
    this(MixAll.DEFAULT_CONSUMER_GROUP, rpcHook, new AllocateMessageQueueAveragely());
}
 
Example #10
Source File: DefaultMQPushConsumer.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public DefaultMQPushConsumer() {
    this(MixAll.DEFAULT_CONSUMER_GROUP, null, new AllocateMessageQueueAveragely());
}
 
Example #11
Source File: AllocateMessageQueueAveragelyTest.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Before
public void init() {
    allocateMessageQueueAveragely = new AllocateMessageQueueAveragely();
    topic = "topic_test";
}
 
Example #12
Source File: DefaultMQPushConsumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public DefaultMQPushConsumer() {
    this(MixAll.DEFAULT_CONSUMER_GROUP, null, new AllocateMessageQueueAveragely());
}
 
Example #13
Source File: DefaultMQPushConsumer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public DefaultMQPushConsumer(RPCHook rpcHook) {
    this(MixAll.DEFAULT_CONSUMER_GROUP, rpcHook, new AllocateMessageQueueAveragely());
}
 
Example #14
Source File: DefaultMQPushConsumer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public DefaultMQPushConsumer() {
    this(MixAll.DEFAULT_CONSUMER_GROUP, null, new AllocateMessageQueueAveragely());
}
 
Example #15
Source File: AllocateMessageQueueAveragelyTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void init() {
    allocateMessageQueueAveragely = new AllocateMessageQueueAveragely();
    topic = "topic_test";
}
 
Example #16
Source File: DefaultMQPushConsumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public DefaultMQPushConsumer(final String consumerGroup) {
    this(consumerGroup, null, new AllocateMessageQueueAveragely());
}
 
Example #17
Source File: DefaultMQPushConsumer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public DefaultMQPushConsumer(RPCHook rpcHook) {
    this(MixAll.DEFAULT_CONSUMER_GROUP, rpcHook, new AllocateMessageQueueAveragely());
}