Java Code Examples for org.apache.rocketmq.remoting.protocol.RemotingSerializable#toJson()

The following examples show how to use org.apache.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: ConsumerFilterManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public String encode(final boolean prettyFormat) {
    // clean
    {
        clean();
    }
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 2
Source File: ConsumeStatusTest.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(10);
    cs.setPullRT(100);
    cs.setPullTPS(1000);
    String json = RemotingSerializable.toJson(cs, true);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
    assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001));
    assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001));
    assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001));
}
 
Example 3
Source File: AllocateMQSubCommand.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    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.printf("%s%n", json);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        adminExt.shutdown();
    }
}
 
Example 4
Source File: QueryConsumeQueueResponseBodyTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void test(){
    QueryConsumeQueueResponseBody body = new QueryConsumeQueueResponseBody();

    SubscriptionData subscriptionData = new SubscriptionData();
    ConsumeQueueData data = new ConsumeQueueData();
    data.setBitMap("defaultBitMap");
    data.setEval(false);
    data.setMsg("this is default msg");
    data.setPhysicOffset(10L);
    data.setPhysicSize(1);
    data.setTagsCode(1L);
    List<ConsumeQueueData> list = new ArrayList<ConsumeQueueData>();
    list.add(data);

    body.setQueueData(list);
    body.setFilterData("default filter data");
    body.setMaxQueueIndex(100L);
    body.setMinQueueIndex(1L);
    body.setSubscriptionData(subscriptionData);

    String json = RemotingSerializable.toJson(body, true);
    QueryConsumeQueueResponseBody fromJson = RemotingSerializable.fromJson(json, QueryConsumeQueueResponseBody.class);
    System.out.println(json);
    //test ConsumeQueue
    ConsumeQueueData jsonData = fromJson.getQueueData().get(0);
    assertThat(jsonData.getMsg()).isEqualTo("this is default msg");
    assertThat(jsonData.getPhysicSize()).isEqualTo(1);
    assertThat(jsonData.getBitMap()).isEqualTo("defaultBitMap");
    assertThat(jsonData.getTagsCode()).isEqualTo(1L);
    assertThat(jsonData.getPhysicSize()).isEqualTo(1);

    //test QueryConsumeQueueResponseBody
    assertThat(fromJson.getFilterData()).isEqualTo("default filter data");
    assertThat(fromJson.getMaxQueueIndex()).isEqualTo(100L);
    assertThat(fromJson.getMinQueueIndex()).isEqualTo(1L);
    assertThat(fromJson.getSubscriptionData()).isEqualTo(subscriptionData);

}
 
Example 5
Source File: ConsumerConnectionTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() {
    ConsumerConnection consumerConnection = new ConsumerConnection();
    HashSet<Connection> connections = new HashSet<Connection>();
    Connection conn = new Connection();
    connections.add(conn);

    ConcurrentHashMap<String/* Topic */, SubscriptionData> subscriptionTable = new ConcurrentHashMap<String, SubscriptionData>();
    SubscriptionData subscriptionData = new SubscriptionData();
    subscriptionTable.put("topicA", subscriptionData);

    ConsumeType consumeType = ConsumeType.CONSUME_ACTIVELY;
    MessageModel messageModel = MessageModel.CLUSTERING;
    ConsumeFromWhere consumeFromWhere = ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET;

    consumerConnection.setConnectionSet(connections);
    consumerConnection.setSubscriptionTable(subscriptionTable);
    consumerConnection.setConsumeType(consumeType);
    consumerConnection.setMessageModel(messageModel);
    consumerConnection.setConsumeFromWhere(consumeFromWhere);

    String json = RemotingSerializable.toJson(consumerConnection, true);
    ConsumerConnection fromJson = RemotingSerializable.fromJson(json, ConsumerConnection.class);
    assertThat(fromJson.getConsumeType()).isEqualTo(ConsumeType.CONSUME_ACTIVELY);
    assertThat(fromJson.getMessageModel()).isEqualTo(MessageModel.CLUSTERING);

    HashSet<Connection> connectionSet = fromJson.getConnectionSet();
    assertThat(connectionSet).isInstanceOf(Set.class);

    SubscriptionData data = fromJson.getSubscriptionTable().get("topicA");
    assertThat(data).isExactlyInstanceOf(SubscriptionData.class);
}
 
Example 6
Source File: ConsumeStatusTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(10);
    cs.setPullRT(100);
    cs.setPullTPS(1000);
    String json = RemotingSerializable.toJson(cs, true);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
    assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001));
    assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001));
    assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001));
}
 
Example 7
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.printf("%s%n", json);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        adminExt.shutdown();
    }
}
 
Example 8
Source File: CheckClientRequestBodyTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() {
    SubscriptionData subscriptionData = new SubscriptionData();
    String expectedClientId = "defalutId";
    String expectedGroup = "defaultGroup";
    CheckClientRequestBody checkClientRequestBody = new CheckClientRequestBody();
    checkClientRequestBody.setClientId(expectedClientId);
    checkClientRequestBody.setGroup(expectedGroup);
    checkClientRequestBody.setSubscriptionData(subscriptionData);
    String json = RemotingSerializable.toJson(checkClientRequestBody, true);
    CheckClientRequestBody fromJson = RemotingSerializable.fromJson(json, CheckClientRequestBody.class);
    assertThat(fromJson.getClientId()).isEqualTo(expectedClientId);
    assertThat(fromJson.getGroup()).isEqualTo(expectedGroup);
    assertThat(fromJson.getSubscriptionData()).isEqualTo(subscriptionData);
}
 
Example 9
Source File: ConsumeStatusTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(10);
    cs.setPullRT(100);
    cs.setPullTPS(1000);
    String json = RemotingSerializable.toJson(cs, true);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
    assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001));
    assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001));
    assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001));
}
 
Example 10
Source File: ConsumeStatusTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(10);
    cs.setPullRT(100);
    cs.setPullTPS(1000);
    String json = RemotingSerializable.toJson(cs, true);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
    assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001));
    assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001));
    assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001));
}
 
Example 11
Source File: ConsumeStatsListTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() {
    ConsumeStats consumeStats = new ConsumeStats();
    ArrayList<ConsumeStats> consumeStatsListValue = new ArrayList<ConsumeStats>();
    consumeStatsListValue.add(consumeStats);
    HashMap<String, List<ConsumeStats>> map = new HashMap<String, List<ConsumeStats>>();
    map.put("subscriptionGroupName", consumeStatsListValue);
    List<Map<String/*subscriptionGroupName*/, List<ConsumeStats>>> consumeStatsListValue2 = new ArrayList<Map<String, List<ConsumeStats>>>();
    consumeStatsListValue2.add(map);

    String brokerAddr = "brokerAddr";
    long totalDiff = 12352L;
    ConsumeStatsList consumeStatsList = new ConsumeStatsList();
    consumeStatsList.setBrokerAddr(brokerAddr);
    consumeStatsList.setTotalDiff(totalDiff);
    consumeStatsList.setConsumeStatsList(consumeStatsListValue2);

    String toJson = RemotingSerializable.toJson(consumeStatsList, true);
    ConsumeStatsList fromJson = RemotingSerializable.fromJson(toJson, ConsumeStatsList.class);

    assertThat(fromJson.getBrokerAddr()).isEqualTo(brokerAddr);
    assertThat(fromJson.getTotalDiff()).isEqualTo(totalDiff);

    List<Map<String, List<ConsumeStats>>> fromJsonConsumeStatsList = fromJson.getConsumeStatsList();
    assertThat(fromJsonConsumeStatsList).isInstanceOf(List.class);

    ConsumeStats fromJsonConsumeStats = fromJsonConsumeStatsList.get(0).get("subscriptionGroupName").get(0);
    assertThat(fromJsonConsumeStats).isExactlyInstanceOf(ConsumeStats.class);
}
 
Example 12
Source File: ConsumerFilterManager.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public String encode(final boolean prettyFormat) {
    // clean
    {
        clean();
    }
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 13
Source File: AllocateMQSubCommand.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    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.printf("%s%n", json);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        adminExt.shutdown();
    }
}
 
Example 14
Source File: ConsumeStatusTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    ConsumeStatus cs = new ConsumeStatus();
    cs.setConsumeFailedTPS(10);
    cs.setPullRT(100);
    cs.setPullTPS(1000);
    String json = RemotingSerializable.toJson(cs, true);
    ConsumeStatus fromJson = RemotingSerializable.fromJson(json, ConsumeStatus.class);
    assertThat(fromJson.getPullRT()).isCloseTo(cs.getPullRT(), within(0.0001));
    assertThat(fromJson.getPullTPS()).isCloseTo(cs.getPullTPS(), within(0.0001));
    assertThat(fromJson.getConsumeFailedTPS()).isCloseTo(cs.getConsumeFailedTPS(), within(0.0001));
}
 
Example 15
Source File: TransactionTableDefConfigService.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public String encode() {
    if (tableDefine == null) {
        return "";
    }
    return RemotingSerializable.toJson(tableDefine, false);
}
 
Example 16
Source File: ConsumerOffsetManager.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 17
Source File: ConsumerOffsetManager.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 18
Source File: ConsumerOffsetManager.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}
 
Example 19
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 20
Source File: ConsumerOffsetManager.java    From rocketmq with Apache License 2.0 2 votes vote down vote up
/**
 * 编码内容
 * 格式为JSON
 *
 * @param prettyFormat 是否格式化
 * @return 编码后的内容
 */
public String encode(final boolean prettyFormat) {
    return RemotingSerializable.toJson(this, prettyFormat);
}