Search in sources :

Example 1 with OneMessageTransfer

use of org.apache.rocketmq.broker.pagecache.OneMessageTransfer in project rocketmq by apache.

the class Broker2Client method checkProducerTransactionState.

public void checkProducerTransactionState(final Channel channel, final CheckTransactionStateRequestHeader requestHeader, final SelectMappedBufferResult selectMappedBufferResult) {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CHECK_TRANSACTION_STATE, requestHeader);
    request.markOnewayRPC();
    try {
        FileRegion fileRegion = new OneMessageTransfer(request.encodeHeader(selectMappedBufferResult.getSize()), selectMappedBufferResult);
        channel.writeAndFlush(fileRegion).addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                selectMappedBufferResult.release();
                if (!future.isSuccess()) {
                    log.error("invokeProducer failed,", future.cause());
                }
            }
        });
    } catch (Throwable e) {
        log.error("invokeProducer exception", e);
        selectMappedBufferResult.release();
    }
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ChannelFuture(io.netty.channel.ChannelFuture) OneMessageTransfer(org.apache.rocketmq.broker.pagecache.OneMessageTransfer) FileRegion(io.netty.channel.FileRegion) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException)

Example 2 with OneMessageTransfer

use of org.apache.rocketmq.broker.pagecache.OneMessageTransfer 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 3 with OneMessageTransfer

use of org.apache.rocketmq.broker.pagecache.OneMessageTransfer 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)

Example 4 with OneMessageTransfer

use of org.apache.rocketmq.broker.pagecache.OneMessageTransfer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class Broker2Client method checkProducerTransactionState.

/**
 * Broker主动回查Producer事务状态,Oneway
 */
public void checkProducerTransactionState(final Channel channel, final CheckTransactionStateRequestHeader requestHeader, final SelectMappedBufferResult selectMappedBufferResult) {
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CHECK_TRANSACTION_STATE, requestHeader);
    request.markOnewayRPC();
    try {
        FileRegion fileRegion = new OneMessageTransfer(request.encodeHeader(selectMappedBufferResult.getSize()), selectMappedBufferResult);
        channel.writeAndFlush(fileRegion).addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                selectMappedBufferResult.release();
                if (!future.isSuccess()) {
                    log.error("invokeProducer failed,", future.cause());
                }
            }
        });
    } catch (Throwable e) {
        log.error("invokeProducer exception", e);
        selectMappedBufferResult.release();
    }
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ChannelFuture(io.netty.channel.ChannelFuture) OneMessageTransfer(org.apache.rocketmq.broker.pagecache.OneMessageTransfer) FileRegion(io.netty.channel.FileRegion) ChannelFutureListener(io.netty.channel.ChannelFutureListener) RemotingSendRequestException(org.apache.rocketmq.remoting.exception.RemotingSendRequestException) RemotingTimeoutException(org.apache.rocketmq.remoting.exception.RemotingTimeoutException)

Aggregations

ChannelFuture (io.netty.channel.ChannelFuture)4 ChannelFutureListener (io.netty.channel.ChannelFutureListener)4 FileRegion (io.netty.channel.FileRegion)4 OneMessageTransfer (org.apache.rocketmq.broker.pagecache.OneMessageTransfer)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 ViewMessageRequestHeader (org.apache.rocketmq.common.protocol.header.ViewMessageRequestHeader)2 RemotingCommandException (org.apache.rocketmq.remoting.exception.RemotingCommandException)2 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)2 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)2 SelectMappedBufferResult (org.apache.rocketmq.store.SelectMappedBufferResult)2