Search in sources :

Example 1 with CheckClientRequestBody

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

the class MQClientAPIImpl method checkClientInBroker.

public void checkClientInBroker(final String brokerAddr, final String consumerGroup, final String clientId, final SubscriptionData subscriptionData, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CHECK_CLIENT_CONFIG, null);
    CheckClientRequestBody requestBody = new CheckClientRequestBody();
    requestBody.setClientId(clientId);
    requestBody.setGroup(consumerGroup);
    requestBody.setSubscriptionData(subscriptionData);
    request.setBody(requestBody.encode());
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    if (ResponseCode.SUCCESS != response.getCode()) {
        throw new MQClientException(response.getCode(), response.getRemark());
    }
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) CheckClientRequestBody(org.apache.rocketmq.common.protocol.body.CheckClientRequestBody) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 2 with CheckClientRequestBody

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

the class MQClientAPIImpl method checkClientInBroker.

public void checkClientInBroker(final String brokerAddr, final String consumerGroup, final String clientId, final SubscriptionData subscriptionData, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CHECK_CLIENT_CONFIG, null);
    CheckClientRequestBody requestBody = new CheckClientRequestBody();
    requestBody.setClientId(clientId);
    requestBody.setGroup(consumerGroup);
    requestBody.setSubscriptionData(subscriptionData);
    request.setBody(requestBody.encode());
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    if (ResponseCode.SUCCESS != response.getCode()) {
        throw new MQClientException(response.getCode(), response.getRemark());
    }
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) CheckClientRequestBody(org.apache.rocketmq.common.protocol.body.CheckClientRequestBody) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 3 with CheckClientRequestBody

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

the class ClientManageProcessor method checkClientConfig.

public RemotingCommand checkClientConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    CheckClientRequestBody requestBody = CheckClientRequestBody.decode(request.getBody(), CheckClientRequestBody.class);
    if (requestBody != null && requestBody.getSubscriptionData() != null) {
        SubscriptionData subscriptionData = requestBody.getSubscriptionData();
        if (ExpressionType.isTagType(subscriptionData.getExpressionType())) {
            response.setCode(ResponseCode.SUCCESS);
            response.setRemark(null);
            return response;
        }
        if (!this.brokerController.getBrokerConfig().isEnablePropertyFilter()) {
            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("The broker does not support consumer to filter message by " + subscriptionData.getExpressionType());
            return response;
        }
        try {
            FilterFactory.INSTANCE.get(subscriptionData.getExpressionType()).compile(subscriptionData.getSubString());
        } catch (Exception e) {
            log.warn("Client {}@{} filter message, but failed to compile expression! sub={}, error={}", requestBody.getClientId(), requestBody.getGroup(), requestBody.getSubscriptionData(), e.getMessage());
            response.setCode(ResponseCode.SUBSCRIPTION_PARSE_FAILED);
            response.setRemark(e.getMessage());
            return response;
        }
    }
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) CheckClientRequestBody(org.apache.rocketmq.common.protocol.body.CheckClientRequestBody) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Example 4 with CheckClientRequestBody

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

the class ClientManageProcessor method checkClientConfig.

public RemotingCommand checkClientConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    CheckClientRequestBody requestBody = CheckClientRequestBody.decode(request.getBody(), CheckClientRequestBody.class);
    if (requestBody != null && requestBody.getSubscriptionData() != null) {
        SubscriptionData subscriptionData = requestBody.getSubscriptionData();
        if (ExpressionType.isTagType(subscriptionData.getExpressionType())) {
            response.setCode(ResponseCode.SUCCESS);
            response.setRemark(null);
            return response;
        }
        if (!this.brokerController.getBrokerConfig().isEnablePropertyFilter()) {
            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark("The broker does not support consumer to filter message by " + subscriptionData.getExpressionType());
            return response;
        }
        try {
            FilterFactory.INSTANCE.get(subscriptionData.getExpressionType()).compile(subscriptionData.getSubString());
        } catch (Exception e) {
            log.warn("Client {}@{} filter message, but failed to compile expression! sub={}, error={}", requestBody.getClientId(), requestBody.getGroup(), requestBody.getSubscriptionData(), e.getMessage());
            response.setCode(ResponseCode.SUBSCRIPTION_PARSE_FAILED);
            response.setRemark(e.getMessage());
            return response;
        }
    }
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) CheckClientRequestBody(org.apache.rocketmq.common.protocol.body.CheckClientRequestBody) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Aggregations

CheckClientRequestBody (org.apache.rocketmq.common.protocol.body.CheckClientRequestBody)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)2 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2