org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader Java Examples

The following examples show how to use org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader. 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: ClientRemotingProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final ConsumeMessageDirectlyResultRequestHeader requestHeader =
        (ConsumeMessageDirectlyResultRequestHeader) request
            .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody()));

    ConsumeMessageDirectlyResult result =
        this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName());

    if (null != result) {
        response.setCode(ResponseCode.SUCCESS);
        response.setBody(result.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }

    return response;
}
 
Example #2
Source File: AdminBrokerProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request
        .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName());
    SelectMappedBufferResult selectMappedBufferResult = null;
    try {
        MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
        selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());

        byte[] body = new byte[selectMappedBufferResult.getSize()];
        selectMappedBufferResult.getByteBuffer().get(body);
        request.setBody(body);
    } catch (UnknownHostException e) {
    } finally {
        if (selectMappedBufferResult != null) {
            selectMappedBufferResult.release();
        }
    }

    return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(),
        requestHeader.getClientId());
}
 
Example #3
Source File: ClientRemotingProcessor.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
        RemotingCommand request) throws RemotingCommandException {
        final RemotingCommand response = RemotingCommand.createResponseCommand(null);
        final ConsumeMessageDirectlyResultRequestHeader requestHeader =
            (ConsumeMessageDirectlyResultRequestHeader) request
                .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

//        请求体编码=》
        final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody()));

//        立即消费消息=》
        ConsumeMessageDirectlyResult result =
            this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName());

        if (null != result) {
            response.setCode(ResponseCode.SUCCESS);
            response.setBody(result.encode());
        } else {
            response.setCode(ResponseCode.SYSTEM_ERROR);
            response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
        }

        return response;
    }
 
Example #4
Source File: AdminBrokerProcessor.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
        RemotingCommand request) throws RemotingCommandException {
        final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request
            .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

        request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName());
        SelectMappedBufferResult selectMappedBufferResult = null;
        try {
            MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
//            从commit的offset位置获取一条消息=》
            selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());

            byte[] body = new byte[selectMappedBufferResult.getSize()];
            selectMappedBufferResult.getByteBuffer().get(body);
            request.setBody(body);
        } catch (UnknownHostException e) {
        } finally {
            if (selectMappedBufferResult != null) {
                selectMappedBufferResult.release();
            }
        }

//        调用消费者=》
        return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(),
            requestHeader.getClientId());
    }
 
Example #5
Source File: ClientRemotingProcessor.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final ConsumeMessageDirectlyResultRequestHeader requestHeader =
        (ConsumeMessageDirectlyResultRequestHeader) request
            .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody()));

    ConsumeMessageDirectlyResult result =
        this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName());

    if (null != result) {
        response.setCode(ResponseCode.SUCCESS);
        response.setBody(result.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }

    return response;
}
 
Example #6
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader)request
        .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName());
    SelectMappedBufferResult selectMappedBufferResult = null;
    try {
        MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
        selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());

        byte[] body = new byte[selectMappedBufferResult.getSize()];
        selectMappedBufferResult.getByteBuffer().get(body);
        request.setBody(body);
    } catch (UnknownHostException e) {
    } finally {
        if (selectMappedBufferResult != null) {
            selectMappedBufferResult.release();
        }
    }

    return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(),
        requestHeader.getClientId());
}
 
Example #7
Source File: ClientRemotingProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final ConsumeMessageDirectlyResultRequestHeader requestHeader =
        (ConsumeMessageDirectlyResultRequestHeader) request
            .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody()));

    ConsumeMessageDirectlyResult result =
        this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName());

    if (null != result) {
        response.setCode(ResponseCode.SUCCESS);
        response.setBody(result.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }

    return response;
}
 
Example #8
Source File: AdminBrokerProcessor.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request
        .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName());
    SelectMappedBufferResult selectMappedBufferResult = null;
    try {
        MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
        selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());

        byte[] body = new byte[selectMappedBufferResult.getSize()];
        selectMappedBufferResult.getByteBuffer().get(body);
        request.setBody(body);
    } catch (UnknownHostException e) {
    } finally {
        if (selectMappedBufferResult != null) {
            selectMappedBufferResult.release();
        }
    }

    return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(),
        requestHeader.getClientId());
}
 
Example #9
Source File: ClientRemotingProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final ConsumeMessageDirectlyResultRequestHeader requestHeader =
        (ConsumeMessageDirectlyResultRequestHeader) request
            .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody()));

    ConsumeMessageDirectlyResult result =
        this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName());

    if (null != result) {
        response.setCode(ResponseCode.SUCCESS);
        response.setBody(result.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }

    return response;
}
 
Example #10
Source File: AdminBrokerProcessor.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request
        .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName());
    SelectMappedBufferResult selectMappedBufferResult = null;
    try {
        MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
        selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());

        byte[] body = new byte[selectMappedBufferResult.getSize()];
        selectMappedBufferResult.getByteBuffer().get(body);
        request.setBody(body);
    } catch (UnknownHostException e) {
    } finally {
        if (selectMappedBufferResult != null) {
            selectMappedBufferResult.release();
        }
    }
    //通过Broker直接向某个Consumer发送一条消息,并立刻消费,返回结果给broker,再返回给调用方
    return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(),
        requestHeader.getClientId());
}
 
Example #11
Source File: ClientRemotingProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final ConsumeMessageDirectlyResultRequestHeader requestHeader =
        (ConsumeMessageDirectlyResultRequestHeader) request
            .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    final MessageExt msg = MessageDecoder.decode(ByteBuffer.wrap(request.getBody()));

    ConsumeMessageDirectlyResult result =
        this.mqClientFactory.consumeMessageDirectly(msg, requestHeader.getConsumerGroup(), requestHeader.getBrokerName());

    if (null != result) {
        response.setCode(ResponseCode.SUCCESS);
        response.setBody(result.encode());
    } else {
        response.setCode(ResponseCode.SYSTEM_ERROR);
        response.setRemark(String.format("The Consumer Group <%s> not exist in this consumer", requestHeader.getConsumerGroup()));
    }

    return response;
}
 
Example #12
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {
    final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request
        .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName());
    SelectMappedBufferResult selectMappedBufferResult = null;
    try {
        MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
        selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());

        byte[] body = new byte[selectMappedBufferResult.getSize()];
        selectMappedBufferResult.getByteBuffer().get(body);
        request.setBody(body);
    } catch (UnknownHostException e) {
    } finally {
        if (selectMappedBufferResult != null) {
            selectMappedBufferResult.release();
        }
    }

    return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(),
        requestHeader.getClientId());
}
 
Example #13
Source File: AdminBrokerProcessor.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * 直接消费信息
 * @param ctx ;
 * @param request ;
 * @return ;
 * @throws RemotingCommandException ;
 */
private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx,
    RemotingCommand request) throws RemotingCommandException {

    final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request
        .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class);

    request.getExtFields().put("brokerName", this.brokerController.getBrokerConfig().getBrokerName());
    SelectMappedBufferResult selectMappedBufferResult = null;
    try {
        MessageId messageId = MessageDecoder.decodeMessageId(requestHeader.getMsgId());
        selectMappedBufferResult = this.brokerController.getMessageStore().selectOneMessageByOffset(messageId.getOffset());

        byte[] body = new byte[selectMappedBufferResult.getSize()];
        selectMappedBufferResult.getByteBuffer().get(body);
        request.setBody(body);
    } catch (UnknownHostException e) {
        //;
    } finally {
        if (selectMappedBufferResult != null) {
            selectMappedBufferResult.release();
        }
    }
    //调用消费者直接消费这条信息
    return this.callConsumer(RequestCode.CONSUME_MESSAGE_DIRECTLY, request, requestHeader.getConsumerGroup(),
        requestHeader.getClientId());
}