org.apache.rocketmq.remoting.protocol.RemotingSerializable Java Examples

The following examples show how to use org.apache.rocketmq.remoting.protocol.RemotingSerializable. 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: ConsumeMessageDirectlyResultTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    ConsumeMessageDirectlyResult result = new ConsumeMessageDirectlyResult();
    boolean defaultAutoCommit = true;
    boolean defaultOrder = false;
    long defaultSpentTimeMills = 1234567L;
    String defaultRemark = "defaultMark";
    CMResult defaultCMResult = CMResult.CR_COMMIT;

    result.setAutoCommit(defaultAutoCommit);
    result.setOrder(defaultOrder);
    result.setRemark(defaultRemark);
    result.setSpentTimeMills(defaultSpentTimeMills);
    result.setConsumeResult(defaultCMResult);

    String json = RemotingSerializable.toJson(result, true);
    ConsumeMessageDirectlyResult fromJson = RemotingSerializable.fromJson(json, ConsumeMessageDirectlyResult.class);
    assertThat(fromJson).isNotNull();

    assertThat(fromJson.getRemark()).isEqualTo(defaultRemark);
    assertThat(fromJson.getSpentTimeMills()).isEqualTo(defaultSpentTimeMills);
    assertThat(fromJson.getConsumeResult()).isEqualTo(defaultCMResult);
    assertThat(fromJson.isOrder()).isEqualTo(defaultOrder);

}
 
Example #2
Source File: SubscriptionGroupWrapperTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testFromJson(){
    SubscriptionGroupWrapper subscriptionGroupWrapper = new SubscriptionGroupWrapper();
    ConcurrentHashMap<String, SubscriptionGroupConfig> subscriptions = new ConcurrentHashMap<String, SubscriptionGroupConfig>();
    SubscriptionGroupConfig subscriptionGroupConfig = new SubscriptionGroupConfig();
    subscriptionGroupConfig.setConsumeBroadcastEnable(true);
    subscriptionGroupConfig.setBrokerId(1234);
    subscriptionGroupConfig.setGroupName("Consumer-group-one");
    subscriptions.put("Consumer-group-one", subscriptionGroupConfig);
    subscriptionGroupWrapper.setSubscriptionGroupTable(subscriptions);
    DataVersion dataVersion = new DataVersion();
    dataVersion.nextVersion();
    subscriptionGroupWrapper.setDataVersion(dataVersion);
    String json = RemotingSerializable.toJson(subscriptionGroupWrapper, true);
    SubscriptionGroupWrapper fromJson = RemotingSerializable.fromJson(json, SubscriptionGroupWrapper.class);
    assertThat(fromJson.getSubscriptionGroupTable()).containsKey("Consumer-group-one");
    assertThat(fromJson.getSubscriptionGroupTable().get("Consumer-group-one").getGroupName()).isEqualTo("Consumer-group-one");
    assertThat(fromJson.getSubscriptionGroupTable().get("Consumer-group-one").getBrokerId()).isEqualTo(1234);
}
 
Example #3
Source File: KVTableTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    HashMap<String, String> table = new HashMap<String, String>();
    table.put("key1", "value1");
    table.put("key2", "value2");

    KVTable kvTable = new KVTable();
    kvTable.setTable(table);

    String json = RemotingSerializable.toJson(kvTable, true);
    KVTable fromJson = RemotingSerializable.fromJson(json, KVTable.class);

    assertThat(fromJson).isNotEqualTo(kvTable);
    assertThat(fromJson.getTable().get("key1")).isEqualTo(kvTable.getTable().get("key1"));
    assertThat(fromJson.getTable().get("key2")).isEqualTo(kvTable.getTable().get("key2"));
}
 
Example #4
Source File: QueryConsumeTimeSpanBodyTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    QueryConsumeTimeSpanBody qctsb = new QueryConsumeTimeSpanBody();
    List<QueueTimeSpan> queueTimeSpans = new ArrayList<QueueTimeSpan>();
    QueueTimeSpan queueTimeSpan = new QueueTimeSpan();
    queueTimeSpan.setMinTimeStamp(1550825710000l);
    queueTimeSpan.setMaxTimeStamp(1550825790000l);
    queueTimeSpan.setConsumeTimeStamp(1550825760000l);
    queueTimeSpan.setDelayTime(5000l);
    MessageQueue messageQueue = new MessageQueue("topicName", "brokerName", 1);
    queueTimeSpan.setMessageQueue(messageQueue);
    queueTimeSpans.add(queueTimeSpan);
    qctsb.setConsumeTimeSpanSet(queueTimeSpans);
    String json = RemotingSerializable.toJson(qctsb, true);
    QueryConsumeTimeSpanBody fromJson = RemotingSerializable.fromJson(json, QueryConsumeTimeSpanBody.class);
    assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMaxTimeStamp()).isEqualTo(1550825790000l);
    assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMinTimeStamp()).isEqualTo(1550825710000l);
    assertThat(fromJson.getConsumeTimeSpanSet().get(0).getDelayTime()).isEqualTo(5000l);
    assertThat(fromJson.getConsumeTimeSpanSet().get(0).getMessageQueue()).isEqualTo(messageQueue);
}
 
Example #5
Source File: AdminBrokerProcessor.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request)
        throws RemotingCommandException {
        final RemotingCommand response = RemotingCommand.createResponseCommand(null);

        log.info("updateAndCreateSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

        SubscriptionGroupConfig config = RemotingSerializable.decode(request.getBody(), SubscriptionGroupConfig.class);
        if (config != null) {
//            =》
            this.brokerController.getSubscriptionGroupManager().updateSubscriptionGroupConfig(config);
        }

        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }
 
Example #6
Source File: ClusterInfoTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormJson() throws Exception {
    ClusterInfo clusterInfo = buildClusterInfo();
    byte[] data = clusterInfo.encode();
    ClusterInfo json = RemotingSerializable.decode(data, ClusterInfo.class);

    assertNotNull(json);
    assertNotNull(json.getClusterAddrTable());
    assertTrue(json.getClusterAddrTable().containsKey("DEFAULT_CLUSTER"));
    assertTrue(json.getClusterAddrTable().get("DEFAULT_CLUSTER").contains("master"));
    assertNotNull(json.getBrokerAddrTable());
    assertTrue(json.getBrokerAddrTable().containsKey("master"));
    assertEquals(json.getBrokerAddrTable().get("master").getBrokerName(), "master");
    assertEquals(json.getBrokerAddrTable().get("master").getCluster(), "DEFAULT_CLUSTER");
    assertEquals(json.getBrokerAddrTable().get("master").getBrokerAddrs().get(MixAll.MASTER_ID), MixAll.getLocalhostByNetworkInterface());
}
 
Example #7
Source File: AdminBrokerProcessor.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 更新获取创建 SubscriptionGroup
 * @param ctx ;
 * @param request ;
 * @return ;
 * @throws RemotingCommandException ;
 */
private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request)
    throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    log.info("updateAndCreateSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

    SubscriptionGroupConfig config = RemotingSerializable.decode(request.getBody(), SubscriptionGroupConfig.class);
    if (config != null) {
        this.brokerController.getSubscriptionGroupManager().updateSubscriptionGroupConfig(config);
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #8
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 #9
Source File: SubscriptionGroupManager.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public void decode(String jsonString) {
    if (jsonString != null) {
        SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class);
        if (obj != null) {
            this.subscriptionGroupTable.putAll(obj.subscriptionGroupTable);
            this.dataVersion.assignNewOne(obj.dataVersion);
            this.printLoadDataWhenFirstBoot(obj);
        }
    }
}
 
Example #10
Source File: AllocateMQSubCommand.java    From rocketmq_trans_message 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 #11
Source File: AllocateMQSubCommand.java    From rocketmq-all-4.1.0-incubating 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 #12
Source File: ConsumeStatusTest.java    From rocketmq-all-4.1.0-incubating 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 #13
Source File: SubscriptionGroupManager.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public void decode(String jsonString) {
    if (jsonString != null) {
        SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class);
        if (obj != null) {
            this.subscriptionGroupTable.putAll(obj.subscriptionGroupTable);
            this.dataVersion.assignNewOne(obj.dataVersion);
            this.printLoadDataWhenFirstBoot(obj);
        }
    }
}
 
Example #14
Source File: SubscriptionGroupManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void decode(String jsonString) {
    if (jsonString != null) {
        SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class);
        if (obj != null) {
            this.subscriptionGroupTable.putAll(obj.subscriptionGroupTable);
            this.dataVersion.assignNewOne(obj.dataVersion);
            this.printLoadDataWhenFirstBoot(obj);
        }
    }
}
 
Example #15
Source File: ConsumerOffsetManager.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public void decode(String jsonString) {
    if (jsonString != null) {
        ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class);
        if (obj != null) {
            this.offsetTable = obj.offsetTable;
        }
    }
}
 
Example #16
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 #17
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 #18
Source File: OffsetMovedEventTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() throws Exception {
  OffsetMovedEvent event = mockOffsetMovedEvent();

  String json = event.toJson();
  OffsetMovedEvent fromJson = RemotingSerializable.fromJson(json, OffsetMovedEvent.class);

  assertEquals(event, fromJson);
}
 
Example #19
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request)
    throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    log.info("updateAndCreateSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

    SubscriptionGroupConfig config = RemotingSerializable.decode(request.getBody(), SubscriptionGroupConfig.class);
    if (config != null) {
        this.brokerController.getSubscriptionGroupManager().updateSubscriptionGroupConfig(config);
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #20
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 #21
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 #22
Source File: SubscriptionGroupManager.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void decode(String jsonString) {
    if (jsonString != null) {
        SubscriptionGroupManager obj = RemotingSerializable.fromJson(jsonString, SubscriptionGroupManager.class);
        if (obj != null) {
            ServerUtil.updateMap(this.subscriptionGroupTable, obj.subscriptionGroupTable);
            this.dataVersion.assignNewOne(obj.dataVersion);
            this.printLoadDataWhenFirstBoot(obj);
        }
    }
}
 
Example #23
Source File: ConsumerOffsetManager.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public void decode(String jsonString) {
    if (jsonString != null) {
        ConsumerOffsetManager obj = RemotingSerializable.fromJson(jsonString, ConsumerOffsetManager.class);
        if (obj != null) {
            ServerUtil.updateMap(this.offsetTable, obj.offsetTable);
        }
    }
}
 
Example #24
Source File: QueryCorrectionOffsetBodyTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromJson() throws Exception {
    QueryCorrectionOffsetBody qcob = new QueryCorrectionOffsetBody();
    Map<Integer, Long> offsetMap = new HashMap<Integer, Long>();
    offsetMap.put(1, 100L);
    offsetMap.put(2, 200L);
    qcob.setCorrectionOffsets(offsetMap);
    String json = RemotingSerializable.toJson(qcob, true);
    QueryCorrectionOffsetBody fromJson = RemotingSerializable.fromJson(json, QueryCorrectionOffsetBody.class);
    assertThat(fromJson.getCorrectionOffsets().get(1)).isEqualTo(100L);
    assertThat(fromJson.getCorrectionOffsets().get(2)).isEqualTo(200L);
    assertThat(fromJson.getCorrectionOffsets().size()).isEqualTo(2);
}
 
Example #25
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 #26
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 #27
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 #28
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private RemotingCommand updateAndCreateSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request)
    throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);

    log.info("updateAndCreateSubscriptionGroup called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel()));

    SubscriptionGroupConfig config = RemotingSerializable.decode(request.getBody(), SubscriptionGroupConfig.class);
    if (config != null) {
        this.brokerController.getSubscriptionGroupManager().updateSubscriptionGroupConfig(config);
    }

    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #29
Source File: TopicRouteDataTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopicRouteDataJsonSerialize() throws Exception {

    TopicRouteData topicRouteData = new TopicRouteData();

    QueueData queueData = new QueueData();
    queueData.setBrokerName("broker-a");
    queueData.setPerm(6);
    queueData.setReadQueueNums(8);
    queueData.setWriteQueueNums(8);
    queueData.setTopicSynFlag(0);

    List<QueueData> queueDataList = new ArrayList<QueueData>();
    queueDataList.add(queueData);

    HashMap<Long, String> brokerAddrs = new HashMap<Long, String>();
    brokerAddrs.put(0L, "192.168.0.47:10911");
    brokerAddrs.put(1L, "192.168.0.47:10921");

    BrokerData brokerData = new BrokerData();
    brokerData.setBrokerAddrs(brokerAddrs);
    brokerData.setBrokerName("broker-a");
    brokerData.setCluster("TestCluster");

    List<BrokerData> brokerDataList = new ArrayList<BrokerData>();
    brokerDataList.add(brokerData);

    topicRouteData.setBrokerDatas(brokerDataList);
    topicRouteData.setFilterServerTable(new HashMap<String, List<String>>());
    topicRouteData.setQueueDatas(queueDataList);

    String topicRouteDataJsonStr = RemotingSerializable.toJson(topicRouteData, true);
    TopicRouteData topicRouteDataFromJson = RemotingSerializable.fromJson(topicRouteDataJsonStr, TopicRouteData.class);

    assertThat(topicRouteDataJsonStr).isNotEqualTo(topicRouteDataFromJson);
    assertThat(topicRouteDataFromJson.getBrokerDatas()).isEqualTo(topicRouteData.getBrokerDatas());
    assertThat(topicRouteDataFromJson.getFilterServerTable()).isEqualTo(topicRouteData.getFilterServerTable());
    assertThat(topicRouteDataFromJson.getQueueDatas()).isEqualTo(topicRouteData.getQueueDatas());

}
 
Example #30
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();
    }
}