Search in sources :

Example 1 with RemotingCommandException

use of org.apache.rocketmq.remoting.exception.RemotingCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClientRemotingProcessor method notifyConsumerIdsChanged.

public RemotingCommand notifyConsumerIdsChanged(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    try {
        final NotifyConsumerIdsChangedRequestHeader requestHeader = (NotifyConsumerIdsChangedRequestHeader) request.decodeCommandCustomHeader(NotifyConsumerIdsChangedRequestHeader.class);
        log.info("receive broker's notification[{}], the consumer group: {} changed, rebalance immediately", RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getConsumerGroup());
        this.mqClientFactory.rebalanceImmediately();
    } catch (Exception e) {
        log.error("notifyConsumerIdsChanged exception", RemotingHelper.exceptionSimpleDesc(e));
    }
    return null;
}
Also used : NotifyConsumerIdsChangedRequestHeader(org.apache.rocketmq.common.protocol.header.NotifyConsumerIdsChangedRequestHeader) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Example 2 with RemotingCommandException

use of org.apache.rocketmq.remoting.exception.RemotingCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AdminBrokerProcessor method callConsumer.

private // 
RemotingCommand callConsumer(// 
final int requestCode, // 
final RemotingCommand request, // 
final String consumerGroup, final String clientId) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager().findChannel(consumerGroup, clientId);
    if (null == clientChannelInfo) {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer <%s> <%s> not online", consumerGroup, clientId));
        return response;
    }
    if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(// 
        String.format(// 
        "The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", // 
        clientId, MQVersion.getVersionDesc(clientChannelInfo.getVersion())));
        return response;
    }
    try {
        RemotingCommand newRequest = RemotingCommand.createRequestCommand(requestCode, null);
        newRequest.setExtFields(request.getExtFields());
        newRequest.setBody(request.getBody());
        return this.brokerController.getBroker2Client().callClient(clientChannelInfo.getChannel(), newRequest);
    } catch (RemotingTimeoutException e) {
        response.setCode(ResponseCode.CONSUME_MSG_TIMEOUT);
        response.setRemark(String.format("consumer <%s> <%s> Timeout: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e)));
        return response;
    } catch (Exception e) {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("invoke consumer <%s> <%s> Exception: %s", consumerGroup, clientId, RemotingHelper.exceptionSimpleDesc(e)));
        return response;
    }
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ClientChannelInfo(org.apache.rocketmq.broker.client.ClientChannelInfo) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Example 3 with RemotingCommandException

use of org.apache.rocketmq.remoting.exception.RemotingCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class QueryMessageProcessor method viewMessageById.

public RemotingCommand viewMessageById(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final ViewMessageRequestHeader requestHeader = (ViewMessageRequestHeader) request.decodeCommandCustomHeader(ViewMessageRequestHeader.class);
    response.setOpaque(request.getOpaque());
    final SelectMappedBufferResult selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(requestHeader.getOffset());
    if (selectMappedBufferResult != null) {
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        try {
            FileRegion fileRegion = new OneMessageTransfer(response.encodeHeader(selectMappedBufferResult.getSize()), selectMappedBufferResult);
            ctx.channel().writeAndFlush(fileRegion).addListener(new ChannelFutureListener() {

                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    selectMappedBufferResult.release();
                    if (!future.isSuccess()) {
                        log.error("Transfer one message from page cache failed, ", future.cause());
                    }
                }
            });
        } catch (Throwable e) {
            log.error("", e);
            selectMappedBufferResult.release();
        }
        return null;
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark("can not find message by the offset, " + requestHeader.getOffset());
    }
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ViewMessageRequestHeader(org.apache.rocketmq.common.protocol.header.ViewMessageRequestHeader) ChannelFuture(io.netty.channel.ChannelFuture) OneMessageTransfer(org.apache.rocketmq.broker.pagecache.OneMessageTransfer) FileRegion(io.netty.channel.FileRegion) SelectMappedBufferResult(org.apache.rocketmq.store.SelectMappedBufferResult) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Example 4 with RemotingCommandException

use of org.apache.rocketmq.remoting.exception.RemotingCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class PullMessageProcessor method executeRequestWhenWakeup.

public void executeRequestWhenWakeup(final Channel channel, final RemotingCommand request) throws RemotingCommandException {
    Runnable run = new Runnable() {

        @Override
        public void run() {
            try {
                final RemotingCommand response = PullMessageProcessor.this.processRequest(channel, request, false);
                if (response != null) {
                    response.setOpaque(request.getOpaque());
                    response.markResponseType();
                    try {
                        channel.writeAndFlush(response).addListener(new ChannelFutureListener() {

                            @Override
                            public void operationComplete(ChannelFuture future) throws Exception {
                                if (!future.isSuccess()) {
                                    LOG.error("ProcessRequestWrapper response to {} failed", future.channel().remoteAddress(), future.cause());
                                    LOG.error(request.toString());
                                    LOG.error(response.toString());
                                }
                            }
                        });
                    } catch (Throwable e) {
                        LOG.error("ProcessRequestWrapper process request over, but response failed", e);
                        LOG.error(request.toString());
                        LOG.error(response.toString());
                    }
                }
            } catch (RemotingCommandException e1) {
                LOG.error("ExecuteRequestWhenWakeup run", e1);
            }
        }
    };
    this.brokerController.getPullMessageExecutor().submit(new RequestTask(run, channel, request));
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ChannelFuture(io.netty.channel.ChannelFuture) RequestTask(org.apache.rocketmq.remoting.netty.RequestTask) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException)

Example 5 with RemotingCommandException

use of org.apache.rocketmq.remoting.exception.RemotingCommandException in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class ClusterTestRequestProcessor method getRouteInfoByTopic.

@Override
public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class);
    TopicRouteData topicRouteData = this.namesrvController.getRouteInfoManager().pickupTopicRouteData(requestHeader.getTopic());
    if (topicRouteData != null) {
        String orderTopicConf = this.namesrvController.getKvConfigManager().getKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, requestHeader.getTopic());
        topicRouteData.setOrderTopicConf(orderTopicConf);
    } else {
        try {
            topicRouteData = adminExt.examineTopicRouteInfo(requestHeader.getTopic());
        } catch (Exception e) {
            log.info("get route info by topic from product environment failed. envName={},", productEnvName);
        }
    }
    if (topicRouteData != null) {
        byte[] content = topicRouteData.encode();
        response.setBody(content);
        response.setCode(ResponseCode.SUCCESS);
        response.setRemark(null);
        return response;
    }
    response.setCode(ResponseCode.TOPIC_NOT_EXIST);
    response.setRemark("No topic route info in name server for the topic: " + requestHeader.getTopic() + FAQUrl.suggestTodo(FAQUrl.APPLY_TOPIC_URL));
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetRouteInfoRequestHeader(org.apache.rocketmq.common.protocol.header.namesrv.GetRouteInfoRequestHeader) RemotingCommandException(org.apache.rocketmq.remoting.exception.RemotingCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Aggregations

RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)26 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)22 ChannelFuture (io.netty.channel.ChannelFuture)8 ChannelFutureListener (io.netty.channel.ChannelFutureListener)8 FileRegion (io.netty.channel.FileRegion)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 UnknownHostException (java.net.UnknownHostException)4 MQClientException (org.apache.rocketmq.client.exception.MQClientException)4 TopicConfig (org.apache.rocketmq.common.TopicConfig)4 QueryMessageRequestHeader (org.apache.rocketmq.common.protocol.header.QueryMessageRequestHeader)4 QueryMessageResponseHeader (org.apache.rocketmq.common.protocol.header.QueryMessageResponseHeader)4 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)4 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)4 CommandCustomHeader (org.apache.rocketmq.remoting.CommandCustomHeader)4 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)4 JSONField (com.alibaba.fastjson.annotation.JSONField)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 LinkedList (java.util.LinkedList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2