Search in sources :

Example 1 with GetConsumerStatusBody

use of org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClientRemotingProcessor method getConsumeStatus.

@Deprecated
public RemotingCommand getConsumeStatus(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetConsumerStatusRequestHeader requestHeader = (GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class);
    Map<MessageQueue, Long> offsetTable = this.mqClientFactory.getConsumerStatus(requestHeader.getTopic(), requestHeader.getGroup());
    GetConsumerStatusBody body = new GetConsumerStatusBody();
    body.setMessageQueueTable(offsetTable);
    response.setBody(body.encode());
    response.setCode(ResponseCode.SUCCESS);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) GetConsumerStatusBody(org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody) GetConsumerStatusRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader)

Example 2 with GetConsumerStatusBody

use of org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class Broker2Client method getConsumeStatus.

public RemotingCommand getConsumeStatus(String topic, String group, String originClientId) {
    final RemotingCommand result = RemotingCommand.createResponseCommand(null);
    GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setGroup(group);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_STATUS_FROM_CLIENT, requestHeader);
    Map<String, Map<MessageQueue, Long>> consumerStatusTable = new HashMap<String, Map<MessageQueue, Long>>();
    ConcurrentMap<Channel, ClientChannelInfo> channelInfoTable = this.brokerController.getConsumerManager().getConsumerGroupInfo(group).getChannelInfoTable();
    if (null == channelInfoTable || channelInfoTable.isEmpty()) {
        result.setCode(ResponseCode.SYSTEM_ERROR);
        result.setRemark(String.format("No Any Consumer online in the consumer group: [%s]", group));
        return result;
    }
    for (Map.Entry<Channel, ClientChannelInfo> entry : channelInfoTable.entrySet()) {
        int version = entry.getValue().getVersion();
        String clientId = entry.getValue().getClientId();
        if (version < MQVersion.Version.V3_0_7_SNAPSHOT.ordinal()) {
            result.setCode(ResponseCode.SYSTEM_ERROR);
            result.setRemark("the client does not support this feature. version=" + MQVersion.getVersionDesc(version));
            log.warn("[get-consumer-status] the client does not support this feature. version={}", RemotingHelper.parseChannelRemoteAddr(entry.getKey()), MQVersion.getVersionDesc(version));
            return result;
        } else if (UtilAll.isBlank(originClientId) || originClientId.equals(clientId)) {
            try {
                RemotingCommand response = this.brokerController.getRemotingServer().invokeSync(entry.getKey(), request, 5000);
                assert response != null;
                switch(response.getCode()) {
                    case ResponseCode.SUCCESS:
                        {
                            if (response.getBody() != null) {
                                GetConsumerStatusBody body = GetConsumerStatusBody.decode(response.getBody(), GetConsumerStatusBody.class);
                                consumerStatusTable.put(clientId, body.getMessageQueueTable());
                                log.info("[get-consumer-status] get consumer status success. topic={}, group={}, channelRemoteAddr={}", topic, group, clientId);
                            }
                        }
                    default:
                        break;
                }
            } catch (Exception e) {
                log.error("[get-consumer-status] get consumer status exception. topic={}, group={}, offset={}", new Object[] { topic, group }, e);
            }
            if (!UtilAll.isBlank(originClientId) && originClientId.equals(clientId)) {
                break;
            }
        }
    }
    result.setCode(ResponseCode.SUCCESS);
    GetConsumerStatusBody resBody = new GetConsumerStatusBody();
    resBody.setConsumerTable(consumerStatusTable);
    result.setBody(resBody.encode());
    return result;
}
Also used : ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) HashMap(java.util.HashMap) Channel(io.netty.channel.Channel) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) GetConsumerStatusBody(org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody) GetConsumerStatusRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 3 with GetConsumerStatusBody

use of org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody in project rocketmq by apache.

the class Broker2Client method getConsumeStatus.

public RemotingCommand getConsumeStatus(String topic, String group, String originClientId) {
    final RemotingCommand result = RemotingCommand.createResponseCommand(null);
    GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setGroup(group);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_STATUS_FROM_CLIENT, requestHeader);
    Map<String, Map<MessageQueue, Long>> consumerStatusTable = new HashMap<String, Map<MessageQueue, Long>>();
    ConcurrentMap<Channel, ClientChannelInfo> channelInfoTable = this.brokerController.getConsumerManager().getConsumerGroupInfo(group).getChannelInfoTable();
    if (null == channelInfoTable || channelInfoTable.isEmpty()) {
        result.setCode(ResponseCode.SYSTEM_ERROR);
        result.setRemark(String.format("No Any Consumer online in the consumer group: [%s]", group));
        return result;
    }
    for (Map.Entry<Channel, ClientChannelInfo> entry : channelInfoTable.entrySet()) {
        int version = entry.getValue().getVersion();
        String clientId = entry.getValue().getClientId();
        if (version < MQVersion.Version.V3_0_7_SNAPSHOT.ordinal()) {
            result.setCode(ResponseCode.SYSTEM_ERROR);
            result.setRemark("the client does not support this feature. version=" + MQVersion.getVersionDesc(version));
            log.warn("[get-consumer-status] the client does not support this feature. version={}", RemotingHelper.parseChannelRemoteAddr(entry.getKey()), MQVersion.getVersionDesc(version));
            return result;
        } else if (UtilAll.isBlank(originClientId) || originClientId.equals(clientId)) {
            try {
                RemotingCommand response = this.brokerController.getRemotingServer().invokeSync(entry.getKey(), request, 5000);
                assert response != null;
                switch(response.getCode()) {
                    case ResponseCode.SUCCESS:
                        {
                            if (response.getBody() != null) {
                                GetConsumerStatusBody body = GetConsumerStatusBody.decode(response.getBody(), GetConsumerStatusBody.class);
                                consumerStatusTable.put(clientId, body.getMessageQueueTable());
                                log.info("[get-consumer-status] get consumer status success. topic={}, group={}, channelRemoteAddr={}", topic, group, clientId);
                            }
                        }
                    default:
                        break;
                }
            } catch (Exception e) {
                log.error("[get-consumer-status] get consumer status exception. topic={}, group={}, offset={}", new Object[] { topic, group }, e);
            }
            if (!UtilAll.isBlank(originClientId) && originClientId.equals(clientId)) {
                break;
            }
        }
    }
    result.setCode(ResponseCode.SUCCESS);
    GetConsumerStatusBody resBody = new GetConsumerStatusBody();
    resBody.setConsumerTable(consumerStatusTable);
    result.setBody(resBody.encode());
    return result;
}
Also used : ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) HashMap(java.util.HashMap) Channel(io.netty.channel.Channel) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) GetConsumerStatusBody(org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody) GetConsumerStatusRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 4 with GetConsumerStatusBody

use of org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method invokeBrokerToGetConsumerStatus.

public Map<String, Map<MessageQueue, Long>> invokeBrokerToGetConsumerStatus(final String addr, final String topic, final String group, final String clientAddr, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setGroup(group);
    requestHeader.setClientAddr(clientAddr);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.INVOKE_BROKER_TO_GET_CONSUMER_STATUS, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                if (response.getBody() != null) {
                    GetConsumerStatusBody body = GetConsumerStatusBody.decode(response.getBody(), GetConsumerStatusBody.class);
                    return body.getConsumerTable();
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetConsumerStatusBody(org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody) GetConsumerStatusRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 5 with GetConsumerStatusBody

use of org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody in project rocketmq by apache.

the class MQClientAPIImpl method invokeBrokerToGetConsumerStatus.

public Map<String, Map<MessageQueue, Long>> invokeBrokerToGetConsumerStatus(final String addr, final String topic, final String group, final String clientAddr, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException {
    GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader();
    requestHeader.setTopic(topic);
    requestHeader.setGroup(group);
    requestHeader.setClientAddr(clientAddr);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.INVOKE_BROKER_TO_GET_CONSUMER_STATUS, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                if (response.getBody() != null) {
                    GetConsumerStatusBody body = GetConsumerStatusBody.decode(response.getBody(), GetConsumerStatusBody.class);
                    return body.getConsumerTable();
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetConsumerStatusBody(org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody) GetConsumerStatusRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Aggregations

GetConsumerStatusBody (org.apache.rocketmq.common.protocol.body.GetConsumerStatusBody)6 GetConsumerStatusRequestHeader (org.apache.rocketmq.common.protocol.header.GetConsumerStatusRequestHeader)6 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)6 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)4 Channel (io.netty.channel.Channel)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ClientChannelInfo (org.apache.rocketmq.broker.client.ClientChannelInfo)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)2 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)2