org.apache.rocketmq.remoting.exception.RemotingConnectException Java Examples

The following examples show how to use org.apache.rocketmq.remoting.exception.RemotingConnectException. 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: UpdateBrokerConfigSubCommandTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException, UnsupportedEncodingException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);
}
 
Example #2
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public boolean cleanUnusedTopic(String cluster) throws RemotingConnectException, RemotingSendRequestException,
    RemotingTimeoutException, MQClientException, InterruptedException {
    boolean result = false;
    try {
        ClusterInfo clusterInfo = examineBrokerClusterInfo();
        if (null == cluster || "".equals(cluster)) {
            for (String targetCluster : clusterInfo.retrieveAllClusterNames()) {
                result = cleanUnusedTopicByCluster(clusterInfo, targetCluster);
            }
        } else {
            result = cleanUnusedTopicByCluster(clusterInfo, cluster);
        }
    } catch (MQBrokerException e) {
        log.error("cleanExpiredConsumerQueue error.", e);
    }

    return result;
}
 
Example #3
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 #4
Source File: MQClientAPIImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr,
    long timeoutMillis) throws InterruptedException,
    RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);

    String acturallyAddr = getActurallyBrokerAddr(brokerAddr);
    RemotingCommand response = this.remotingClient
        .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), acturallyAddr), request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
        }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #5
Source File: MetricsCollectTask.java    From rocketmq-exporter with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() throws InterruptedException, RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, MQBrokerException {
    log.info("MetricsCollectTask init starting....");
    long start = System.currentTimeMillis();
    ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
    StringBuilder infoOut = new StringBuilder();
    for (String clusterName : clusterInfo.getClusterAddrTable().keySet()) {
        infoOut.append(String.format("cluster name= %s, broker name = %s%n", clusterName, clusterInfo.getClusterAddrTable().get(clusterName)));
        if (clusterName != null && MetricsCollectTask.clusterName == null) {
            MetricsCollectTask.clusterName = clusterName;
        }
    }
    for (String brokerName : clusterInfo.getBrokerAddrTable().keySet()) {
        infoOut.append(String.format("broker name = %s, master broker address= %s%n", brokerName, clusterInfo.getBrokerAddrTable().get(brokerName).getBrokerAddrs().get(MixAll.MASTER_ID)));
    }
    log.info(infoOut.toString());
    if (clusterName == null) {
        log.error("get cluster info error" );
    }
    log.info(String.format("MetricsCollectTask init finished....cost:%d", System.currentTimeMillis() - start));
}
 
Example #6
Source File: BrokerStatusSubCommandTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    KVTable kvTable = new KVTable();
    kvTable.setTable(new HashMap<String, String>());
    when(mQClientAPIImpl.getBrokerRuntimeInfo(anyString(), anyLong())).thenReturn(kvTable);
}
 
Example #7
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic,
    final long timeoutMillis)
    throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException,
    MQBrokerException {
    GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);
    requestHeader.setTopic(topic);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class);
            return consumeStats;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #8
Source File: GetNamesrvConfigCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException, UnsupportedEncodingException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    Map<String, Properties> propertiesMap = new HashMap<>();
    List<String> nameServers = new ArrayList<>();
    when(mQClientAPIImpl.getNameServerConfig(ArgumentMatchers.<String>anyList(), anyLong())).thenReturn(propertiesMap);
}
 
Example #9
Source File: GetNamesrvConfigCommandTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException, UnsupportedEncodingException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    Map<String, Properties> propertiesMap = new HashMap<>();
    List<String> nameServers = new ArrayList<>();
    when(mQClientAPIImpl.getNameServerConfig(ArgumentMatchers.<String>anyList(), anyLong())).thenReturn(propertiesMap);
}
 
Example #10
Source File: CleanExpiredCQSubCommandTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    when(mQClientAPIImpl.cleanExpiredConsumeQueue(anyString(), anyLong())).thenReturn(true);
}
 
Example #11
Source File: CleanUnusedTopicCommandTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void init() throws NoSuchFieldException, IllegalAccessException, InterruptedException, RemotingTimeoutException, MQClientException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    mQClientAPIImpl = mock(MQClientAPIImpl.class);
    defaultMQAdminExt = new DefaultMQAdminExt();
    defaultMQAdminExtImpl = new DefaultMQAdminExtImpl(defaultMQAdminExt, 1000);

    Field field = DefaultMQAdminExtImpl.class.getDeclaredField("mqClientInstance");
    field.setAccessible(true);
    field.set(defaultMQAdminExtImpl, mqClientInstance);
    field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl");
    field.setAccessible(true);
    field.set(mqClientInstance, mQClientAPIImpl);
    field = DefaultMQAdminExt.class.getDeclaredField("defaultMQAdminExtImpl");
    field.setAccessible(true);
    field.set(defaultMQAdminExt, defaultMQAdminExtImpl);

    when(mQClientAPIImpl.cleanUnusedTopicByAddr(anyString(), anyLong())).thenReturn(true);
}
 
Example #12
Source File: BrokerOuterAPI.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(
        final String addr) throws InterruptedException, RemotingTimeoutException,
        RemotingSendRequestException, RemotingConnectException, MQBrokerException {
        RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
//        同步执行=》
        RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000);
        assert response != null;
        switch (response.getCode()) {
            case ResponseCode.SUCCESS: {
//                消息json解码
                return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
            }
            default:
                break;
        }

        throw new MQBrokerException(response.getCode(), response.getRemark());
    }
 
Example #13
Source File: MQClientAPIImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup,
    final long timeoutMillis)
    throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException,
    MQBrokerException {
    GetConsumerConnectionListRequestHeader requestHeader = new GetConsumerConnectionListRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_CONNECTION_LIST, requestHeader);

    String acturallyAddr = getActurallyBrokerAddr(addr);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), acturallyAddr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return ConsumerConnection.decode(response.getBody(), ConsumerConnection.class);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #14
Source File: MQClientAPIImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public boolean cleanExpiredConsumeQueue(final String addr,
    long timeoutMillis) throws MQClientException, RemotingConnectException,
    RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_EXPIRED_CONSUMEQUEUE, null);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return true;
        }
        default:
            break;
    }

    throw new MQClientException(response.getCode(), response.getRemark());
}
 
Example #15
Source File: MQClientAPIImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public KVTable getBrokerRuntimeInfo(final String addr, final long timeoutMillis) throws RemotingConnectException,
    RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_RUNTIME_INFO, null);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return KVTable.decode(response.getBody(), KVTable.class);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #16
Source File: MQClientAPIImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public ProducerConnection getProducerConnectionList(final String addr, final String producerGroup,
    final long timeoutMillis)
    throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException,
    MQBrokerException {
    GetProducerConnectionListRequestHeader requestHeader = new GetProducerConnectionListRequestHeader();
    requestHeader.setProducerGroup(producerGroup);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_PRODUCER_CONNECTION_LIST, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
        request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return ProducerConnection.decode(response.getBody(), ProducerConnection.class);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #17
Source File: BrokerOuterAPI.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * 获取全部的topicConfig 如果是备节点,会向主节点同步config
 * @param addr addr
 * @return ;
 * @throws RemotingConnectException ;
 * @throws RemotingSendRequestException ;
 * @throws RemotingTimeoutException ;
 * @throws InterruptedException ;
 * @throws MQBrokerException ;
 */
public TopicConfigSerializeWrapper getAllTopicConfig(
    final String addr) throws RemotingConnectException, RemotingSendRequestException,
    RemotingTimeoutException, InterruptedException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(true, addr), request, 3000);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return TopicConfigSerializeWrapper.decode(response.getBody(), TopicConfigSerializeWrapper.class);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #18
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public ClusterInfo getBrokerClusterInfo(
    final long timeoutMillis) throws InterruptedException, RemotingTimeoutException,
    RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null);

    RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return ClusterInfo.decode(response.getBody(), ClusterInfo.class);
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #19
Source File: DefaultMQAdminExtImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public boolean cleanExpiredConsumerQueue(
    String cluster) throws RemotingConnectException, RemotingSendRequestException,
    RemotingTimeoutException, MQClientException, InterruptedException {
    boolean result = false;
    try {
        ClusterInfo clusterInfo = examineBrokerClusterInfo();
        if (null == cluster || "".equals(cluster)) {
            for (String targetCluster : clusterInfo.retrieveAllClusterNames()) {
                result = cleanExpiredConsumerQueueByCluster(clusterInfo, targetCluster);
            }
        } else {
            result = cleanExpiredConsumerQueueByCluster(clusterInfo, cluster);
        }
    } catch (MQBrokerException e) {
        log.error("cleanExpiredConsumerQueue error.", e);
    }

    return result;
}
 
Example #20
Source File: GetBrokerConfigCommand.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
protected void getAndPrint(final MQAdminExt defaultMQAdminExt, final String printPrefix, final String addr)
    throws InterruptedException, RemotingConnectException,
    UnsupportedEncodingException, RemotingTimeoutException,
    MQBrokerException, RemotingSendRequestException {

    System.out.print(printPrefix);

    Properties properties = defaultMQAdminExt.getBrokerConfig(addr);
    if (properties == null) {
        System.out.printf("Broker[%s] has no config property!\n", addr);
        return;
    }

    for (Object key : properties.keySet()) {
        System.out.printf("%-50s=  %s\n", key, properties.get(key));
    }

    System.out.printf("%n");
}
 
Example #21
Source File: BrokerOuterAPI.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public void unregisterBroker(
    final String namesrvAddr,
    final String clusterName,
    final String brokerAddr,
    final String brokerName,
    final long brokerId
) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException {
    UnRegisterBrokerRequestHeader requestHeader = new UnRegisterBrokerRequestHeader();
    requestHeader.setBrokerAddr(brokerAddr);
    requestHeader.setBrokerId(brokerId);
    requestHeader.setBrokerName(brokerName);
    requestHeader.setClusterName(clusterName);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNREGISTER_BROKER, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(namesrvAddr, request, getTimeout());
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #22
Source File: DefaultMQAdminExtImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Override
public boolean cleanExpiredConsumerQueue(
    String cluster) throws RemotingConnectException, RemotingSendRequestException,
    RemotingTimeoutException, MQClientException, InterruptedException {
    boolean result = false;
    try {
        ClusterInfo clusterInfo = examineBrokerClusterInfo();
        if (null == cluster || "".equals(cluster)) {
            for (String targetCluster : clusterInfo.retrieveAllClusterNames()) {
                result = cleanExpiredConsumerQueueByCluster(clusterInfo, targetCluster);
            }
        } else {
            result = cleanExpiredConsumerQueueByCluster(clusterInfo, cluster);
        }
    } catch (MQBrokerException e) {
        log.error("cleanExpiredConsumerQueue error.", e);
    }

    return result;
}
 
Example #23
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public AllMaxOffset getAllMaxOffset(
    final String brokerAddr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException, RemotingCommandException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_MAX_OFFSET, null);
    RemotingCommand response = this.remotingClient.invokeSync(brokerAddr, request, 3000);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            byte[] body = response.getBody();
            if (body != null) {
                return AllMaxOffset.decode(body, AllMaxOffset.class);
            }
        }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #24
Source File: MQClientAPIImpl.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr,
    long timeoutMillis) throws InterruptedException,
    RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
    RemotingCommand response = this.remotingClient
        .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            return SubscriptionGroupWrapper.decode(response.getBody(), SubscriptionGroupWrapper.class);
        }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #25
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey, long timeoutMillis)
    throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException,
    InterruptedException {
    ViewBrokerStatsDataRequestHeader requestHeader = new ViewBrokerStatsDataRequestHeader();
    requestHeader.setStatsName(statsName);
    requestHeader.setStatsKey(statsKey);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.VIEW_BROKER_STATS_DATA, requestHeader);

    RemotingCommand response = this.remotingClient
        .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            byte[] body = response.getBody();
            if (body != null) {
                return BrokerStatsData.decode(body, BrokerStatsData.class);
            }
        }
        default:
            break;
    }

    throw new MQClientException(response.getCode(), response.getRemark());
}
 
Example #26
Source File: MQClientAPIImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder,
    long timeoutMillis) throws MQClientException,
    RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    GetConsumeStatsInBrokerHeader requestHeader = new GetConsumeStatsInBrokerHeader();
    requestHeader.setIsOrder(isOrder);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CONSUME_STATS, requestHeader);

    RemotingCommand response = this.remotingClient
        .invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            byte[] body = response.getBody();
            if (body != null) {
                return ConsumeStatsList.decode(body, ConsumeStatsList.class);
            }
        }
        default:
            break;
    }

    throw new MQClientException(response.getCode(), response.getRemark());
}
 
Example #27
Source File: RemotingServerTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeAsync() throws InterruptedException, RemotingConnectException,
    RemotingTimeoutException, RemotingTooMuchRequestException, RemotingSendRequestException {

    final CountDownLatch latch = new CountDownLatch(1);
    RemotingCommand request = RemotingCommand.createRequestCommand(0, null);
    request.setRemark("messi");
    remotingClient.invokeAsync("localhost:8888", request, 1000 * 3, new InvokeCallback() {
        @Override
        public void operationComplete(ResponseFuture responseFuture) {
            latch.countDown();
            assertTrue(responseFuture != null);
            assertThat(responseFuture.getResponseCommand().getLanguage()).isEqualTo(LanguageCode.JAVA);
            assertThat(responseFuture.getResponseCommand().getExtFields()).hasSize(2);
        }
    });
    latch.await();
}
 
Example #28
Source File: CommandUtil.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static Map<String/*master addr*/, List<String>/*slave addr*/> fetchMasterAndSlaveDistinguish(
    final MQAdminExt adminExt, final String clusterName)
    throws InterruptedException, RemotingConnectException,
    RemotingTimeoutException, RemotingSendRequestException,
    MQBrokerException {
    Map<String, List<String>> masterAndSlaveMap = new HashMap<String, List<String>>(4);

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

    if (brokerNameSet == null) {
        System.out.printf("[error] %s", ERROR_MESSAGE);
        return masterAndSlaveMap;
    }

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

        if (brokerData == null || brokerData.getBrokerAddrs() == null) {
            continue;
        }

        String masterAddr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
        masterAndSlaveMap.put(masterAddr, new ArrayList<String>());

        for (Long id : brokerData.getBrokerAddrs().keySet()) {
            if (brokerData.getBrokerAddrs().get(id) == null || id == MixAll.MASTER_ID) {
                continue;
            }

            masterAndSlaveMap.get(masterAddr).add(brokerData.getBrokerAddrs().get(id));
        }
    }

    return masterAndSlaveMap;
}
 
Example #29
Source File: CommandUtil.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static Map<String/*master addr*/, List<String>/*slave addr*/> fetchMasterAndSlaveDistinguish(
    final MQAdminExt adminExt, final String clusterName)
    throws InterruptedException, RemotingConnectException,
    RemotingTimeoutException, RemotingSendRequestException,
    MQBrokerException {
    Map<String, List<String>> masterAndSlaveMap = new HashMap<String, List<String>>(4);

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

    if (brokerNameSet == null) {
        System.out
            .printf("[error] Make sure the specified clusterName exists or the nameserver which connected is correct.");
        return masterAndSlaveMap;
    }

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

        if (brokerData == null || brokerData.getBrokerAddrs() == null) {
            continue;
        }

        String masterAddr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID);
        masterAndSlaveMap.put(masterAddr, new ArrayList<String>());

        for (Long id : brokerData.getBrokerAddrs().keySet()) {
            if (brokerData.getBrokerAddrs().get(id) == null
                || id.longValue() == MixAll.MASTER_ID) {
                continue;
            }

            masterAndSlaveMap.get(masterAddr).add(brokerData.getBrokerAddrs().get(id));
        }
    }

    return masterAndSlaveMap;
}
 
Example #30
Source File: DefaultMQAdminExt.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String topic, int queueId, long index,
    int count, String consumerGroup)
    throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException {
    return this.defaultMQAdminExtImpl.queryConsumeQueue(
        brokerAddr, topic, queueId, index, count, consumerGroup
    );
}