Java Code Examples for com.alibaba.rocketmq.remoting.protocol.RemotingSerializable#toJson()

The following examples show how to use com.alibaba.rocketmq.remoting.protocol.RemotingSerializable#toJson() . 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: 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 2
Source File: ConsumeStatusTest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void decode_test() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(0L);
    String json = RemotingSerializable.toJson(cs, true);
    System.out.println(json);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
}
 
Example 3
Source File: FilterAPITest.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSubscriptionData() throws Exception {
    SubscriptionData subscriptionData =
            FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3");
    subscriptionData.setFilterClassSource("java hello");
    String json = RemotingSerializable.toJson(subscriptionData, true);
    System.out.println(json);
}
 
Example 4
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 5
Source File: ConsumeStatusTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void decode_test() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(0L);
    String json = RemotingSerializable.toJson(cs, true);
    System.out.println(json);
    RemotingSerializable.fromJson(json, ConsumeStatus.class);
}
 
Example 6
Source File: FilterAPITest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscriptionData() throws Exception {
    SubscriptionData subscriptionData =
            FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3");
    subscriptionData.setFilterClassSource("java hello");
    String json = RemotingSerializable.toJson(subscriptionData, true);
    System.out.println(json);
}
 
Example 7
Source File: ConsumeStatusTest.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
@Test
public void decode_test() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(0L);
    String json = RemotingSerializable.toJson(cs, true);
    System.out.println(json);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
}
 
Example 8
Source File: FilterAPITest.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscriptionData() throws Exception {
    SubscriptionData subscriptionData =
            FilterAPI.buildSubscriptionData("ConsumerGroup1", "TestTopic", "TAG1 || Tag2 || tag3");
    subscriptionData.setFilterClassSource("java hello");
    String json = RemotingSerializable.toJson(subscriptionData, true);
    System.out.println(json);
}
 
Example 9
Source File: SubscriptionGroupManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 10
Source File: ConsumerOffsetManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 11
Source File: SubscriptionGroupManager.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 12
Source File: ConsumerOffsetManager.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 13
Source File: SubscriptionGroupManager.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 14
Source File: ConsumerOffsetManager.java    From RocketMQ-Master-analyze with Apache License 2.0 2 votes vote down vote up
/**
 * 编码,将对象(ConsumerOffsetManager)转为json格式
 * 
 * @param prettyFormat
 * @return
 */
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}