protected void response( PullMessageTask pullTask, List<TppConsumerMessageBatch> batches, Offset offset) { Command cmd = null; switch (pullTask.getPullMessageCommandVersion()) { case 1: cmd = new PullMessageResultCommand(); if (batches != null) { ((PullMessageResultCommand) cmd).addBatches(batches); } break; case 2: default: cmd = new PullMessageResultCommandV2(); if (batches != null) { ((PullMessageResultCommandV2) cmd).addBatches(batches); } ((PullMessageResultCommandV2) cmd).setOffset(offset); break; } cmd.getHeader().setCorrelationId(pullTask.getCorrelationId()); pullTask.getChannel().writeAndFlush(cmd); }
@Override public void process(CommandProcessorContext ctx) { PullSpecificMessageCommand reqCmd = (PullSpecificMessageCommand) ctx.getCommand(); long correlationId = reqCmd.getHeader().getCorrelationId(); String topic = reqCmd.getTopic(); int partition = reqCmd.getPartition(); List<Offset> offsets = reqCmd.getOffsets(); try { Lease lease = m_leaseContainer.acquireLease(topic, partition, m_config.getSessionId()); if (lease != null) { List<TppConsumerMessageBatch> batches = m_messageQueueManager.findMessagesByOffsets( // topic, partition, offsets); if (!batches.isEmpty()) { PullMessageResultCommandV2 cmd = new PullMessageResultCommandV2(); cmd.setBrokerAccepted(true); cmd.addBatches(batches); cmd.getHeader().setCorrelationId(correlationId); ctx.getChannel().writeAndFlush(cmd); return; } } else { log.debug( "No broker lease to handle pull message cmd. [op-id: {}] {} {}", correlationId, topic, partition); } } catch (Exception e) { log.debug( "Handle pull message reqeust failed. [op-id: {}] {} {}", correlationId, topic, partition, e); } PullMessageResultCommandV2 cmd = new PullMessageResultCommandV2(); cmd.setBrokerAccepted(false); cmd.getHeader().setCorrelationId(correlationId); ctx.getChannel().writeAndFlush(cmd); }