Search in sources :

Example 1 with GetConsumerListByGroupRequestHeader

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

the class MQClientAPIImpl method getConsumerIdListByGroup.

public // 
List<String> getConsumerIdListByGroup(// 
final String addr, // 
final String consumerGroup, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQBrokerException, InterruptedException {
    GetConsumerListByGroupRequestHeader requestHeader = new GetConsumerListByGroupRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_LIST_BY_GROUP, 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) {
                    GetConsumerListByGroupResponseBody body = GetConsumerListByGroupResponseBody.decode(response.getBody(), GetConsumerListByGroupResponseBody.class);
                    return body.getConsumerIdList();
                }
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetConsumerListByGroupResponseBody(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseBody) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) GetConsumerListByGroupRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader)

Example 2 with GetConsumerListByGroupRequestHeader

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

the class ConsumerManageProcessor method getConsumerListByGroup.

public RemotingCommand getConsumerListByGroup(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(GetConsumerListByGroupResponseHeader.class);
    final GetConsumerListByGroupRequestHeader requestHeader = (GetConsumerListByGroupRequestHeader) request.decodeCommandCustomHeader(GetConsumerListByGroupRequestHeader.class);
    ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup());
    if (consumerGroupInfo != null) {
        List<String> clientIds = consumerGroupInfo.getAllClientId();
        if (!clientIds.isEmpty()) {
            GetConsumerListByGroupResponseBody body = new GetConsumerListByGroupResponseBody();
            body.setConsumerIdList(clientIds);
            response.setBody(body.encode());
            response.setCode(ResponseCode.SUCCESS);
            response.setRemark(null);
            return response;
        } else {
            log.warn("getAllClientId failed, {} {}", requestHeader.getConsumerGroup(), RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
        }
    } else {
        log.warn("getConsumerGroupInfo failed, {} {}", requestHeader.getConsumerGroup(), RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
    }
    response.setCode(ResponseCode.SYSTEM_ERROR);
    response.setRemark("no consumer for this group, " + requestHeader.getConsumerGroup());
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetConsumerListByGroupResponseBody(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseBody) GetConsumerListByGroupRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader) ConsumerGroupInfo(org.apache.rocketmq.broker.client.ConsumerGroupInfo)

Example 3 with GetConsumerListByGroupRequestHeader

use of org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader in project rocketmq by apache.

the class ConsumerManageProcessor method getConsumerListByGroup.

public RemotingCommand getConsumerListByGroup(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(GetConsumerListByGroupResponseHeader.class);
    final GetConsumerListByGroupRequestHeader requestHeader = (GetConsumerListByGroupRequestHeader) request.decodeCommandCustomHeader(GetConsumerListByGroupRequestHeader.class);
    ConsumerGroupInfo consumerGroupInfo = this.brokerController.getConsumerManager().getConsumerGroupInfo(requestHeader.getConsumerGroup());
    if (consumerGroupInfo != null) {
        List<String> clientIds = consumerGroupInfo.getAllClientId();
        if (!clientIds.isEmpty()) {
            GetConsumerListByGroupResponseBody body = new GetConsumerListByGroupResponseBody();
            body.setConsumerIdList(clientIds);
            response.setBody(body.encode());
            response.setCode(ResponseCode.SUCCESS);
            response.setRemark(null);
            return response;
        } else {
            log.warn("getAllClientId failed, {} {}", requestHeader.getConsumerGroup(), RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
        }
    } else {
        log.warn("getConsumerGroupInfo failed, {} {}", requestHeader.getConsumerGroup(), RemotingHelper.parseChannelRemoteAddr(ctx.channel()));
    }
    response.setCode(ResponseCode.SYSTEM_ERROR);
    response.setRemark("no consumer for this group, " + requestHeader.getConsumerGroup());
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetConsumerListByGroupResponseBody(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseBody) GetConsumerListByGroupRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader) ConsumerGroupInfo(org.apache.rocketmq.broker.client.ConsumerGroupInfo)

Example 4 with GetConsumerListByGroupRequestHeader

use of org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader in project rocketmq by apache.

the class MQClientAPIImpl method getConsumerIdListByGroup.

public List<String> getConsumerIdListByGroup(final String addr, final String consumerGroup, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQBrokerException, InterruptedException {
    GetConsumerListByGroupRequestHeader requestHeader = new GetConsumerListByGroupRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUMER_LIST_BY_GROUP, 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) {
                    GetConsumerListByGroupResponseBody body = GetConsumerListByGroupResponseBody.decode(response.getBody(), GetConsumerListByGroupResponseBody.class);
                    return body.getConsumerIdList();
                }
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetConsumerListByGroupResponseBody(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseBody) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) GetConsumerListByGroupRequestHeader(org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader)

Aggregations

GetConsumerListByGroupRequestHeader (org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupRequestHeader)4 GetConsumerListByGroupResponseBody (org.apache.rocketmq.common.protocol.header.GetConsumerListByGroupResponseBody)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 ConsumerGroupInfo (org.apache.rocketmq.broker.client.ConsumerGroupInfo)2 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)2