@Override
public void onReceived(Iterator<FetchedMessage> messages) {
int count = 0;
while (messages.hasNext()) {
FetchedMessage message = messages.next();
try {
GenericRecord genericRecord = serializer.toGenericRecord(message.getPayload());
ILoggingEvent event = serializer.fromGenericRecord(genericRecord);
LoggingContext loggingContext = LoggingContextHelper.getLoggingContext(event.getMDCPropertyMap());
synchronized (messageTable) {
long key = event.getTimeStamp() / eventBucketIntervalMs;
List<KafkaLogEvent> msgList = messageTable.get(key, loggingContext.getLogPathFragment());
if (msgList == null) {
msgList = Lists.newArrayList();
messageTable.put(key, loggingContext.getLogPathFragment(), msgList);
}
msgList.add(new KafkaLogEvent(genericRecord, event, loggingContext,
message.getTopicPartition().getPartition(), message.getNextOffset()));
}
} catch (Throwable e) {
LOG.warn("Exception while processing message with nextOffset {}. Skipping it.", message.getNextOffset(), e);
}
++count;
}
LOG.debug("Got {} messages from kafka", count);
}