Example #1
0
  static void appendMessages(Tpp tpp, Collection<MessageBatchWithRawData> batches)
      throws Exception {
    List<MessagePriority> msgs = new ArrayList<>();
    for (MessageBatchWithRawData batch : batches) {
      List<PartialDecodedMessage> pdmsgs = batch.getMessages();
      for (PartialDecodedMessage pdmsg : pdmsgs) {
        MessagePriority msg = new MessagePriority();
        msg.setAttributes(pdmsg.readDurableProperties());
        msg.setCreationDate(new Date(pdmsg.getBornTime()));
        msg.setPartition(tpp.getPartition());
        msg.setPayload(pdmsg.readBody());
        msg.setPriority(tpp.isPriority() ? 0 : 1);
        msg.setProducerId(0);
        msg.setProducerIp("");
        msg.setRefKey(pdmsg.getKey());
        msg.setTopic(tpp.getTopic());
        msg.setCodecType(pdmsg.getBodyCodecType());

        msgs.add(msg);
      }
    }

    long start = System.currentTimeMillis();
    MessagePriority[] array = msgs.toArray(new MessagePriority[msgs.size()]);
    System.out.println("ToArray: " + (System.currentTimeMillis() - start));
    start = System.currentTimeMillis();
    PlexusComponentLocator.lookup(MessagePriorityDao.class).insert(array);
    System.out.println("Insert: " + (System.currentTimeMillis() - start));
  }
  private void bizLog(
      CommandProcessorContext ctx,
      Map<Integer, MessageBatchWithRawData> rawBatches,
      int partition) {
    String ip = NettyUtils.parseChannelRemoteAddr(ctx.getChannel(), false);
    for (Entry<Integer, MessageBatchWithRawData> entry : rawBatches.entrySet()) {
      MessageBatchWithRawData batch = entry.getValue();
      List<PartialDecodedMessage> msgs = batch.getMessages();
      for (PartialDecodedMessage msg : msgs) {
        BizEvent event = new BizEvent("Message.Received");
        event.addData("topic", batch.getTopic());
        event.addData("partition", partition);
        event.addData("priority", entry.getKey());
        event.addData("producerIp", ip);
        event.addData("bornTime", msg.getBornTime());
        event.addData("refKey", msg.getKey());

        m_bizLogger.log(event);
      }
    }
  }