@Override public void appendMessages(Tpp tpp, Collection<MessageBatchWithRawData> batches) throws Exception { ByteBuf bodyBuf = Unpooled.buffer(); KafkaMessageBrokerSender sender = getSender(tpp.getTopic()); try { for (MessageBatchWithRawData batch : batches) { List<PartialDecodedMessage> pdmsgs = batch.getMessages(); for (PartialDecodedMessage pdmsg : pdmsgs) { m_messageCodec.encodePartial(pdmsg, bodyBuf); byte[] bytes = new byte[bodyBuf.readableBytes()]; bodyBuf.readBytes(bytes); bodyBuf.clear(); ByteBuf propertiesBuf = pdmsg.getDurableProperties(); HermesPrimitiveCodec codec = new HermesPrimitiveCodec(propertiesBuf); Map<String, String> propertiesMap = codec.readStringStringMap(); sender.send(tpp.getTopic(), propertiesMap.get("pK"), bytes); BrokerStatusMonitor.INSTANCE.kafkaSend(tpp.getTopic()); } } } finally { bodyBuf.release(); } }
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); } } }
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)); }