Search in sources :

Example 6 with SelectMappedBufferResult

use of org.apache.rocketmq.store.SelectMappedBufferResult in project rocketmq by apache.

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)

Aggregations

SelectMappedBufferResult (org.apache.rocketmq.store.SelectMappedBufferResult)6 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 FileRegion (io.netty.channel.FileRegion)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 ConsumerFilterData (org.apache.rocketmq.broker.filter.ConsumerFilterData)2 ExpressionMessageFilter (org.apache.rocketmq.broker.filter.ExpressionMessageFilter)2 OneMessageTransfer (org.apache.rocketmq.broker.pagecache.OneMessageTransfer)2 MessageId (org.apache.rocketmq.common.message.MessageId)2 ConsumeQueueData (org.apache.rocketmq.common.protocol.body.ConsumeQueueData)2 QueryConsumeQueueResponseBody (org.apache.rocketmq.common.protocol.body.QueryConsumeQueueResponseBody)2 ConsumeMessageDirectlyResultRequestHeader (org.apache.rocketmq.common.protocol.header.ConsumeMessageDirectlyResultRequestHeader)2 QueryConsumeQueueRequestHeader (org.apache.rocketmq.common.protocol.header.QueryConsumeQueueRequestHeader)2 ViewMessageRequestHeader (org.apache.rocketmq.common.protocol.header.ViewMessageRequestHeader)2 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)2 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2 ConsumeQueue (org.apache.rocketmq.store.ConsumeQueue)2 ConsumeQueueExt (org.apache.rocketmq.store.ConsumeQueueExt)2